mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-06-10 13:09:11 -04:00
rename CloseError() to Interrupt()
This commit is contained in:
@@ -6,6 +6,11 @@ type Closable interface {
|
||||
Close() error
|
||||
}
|
||||
|
||||
// Interruptible is an interface for objects that can be stopped before its completion.
|
||||
type Interruptible interface {
|
||||
Interrupt()
|
||||
}
|
||||
|
||||
// Close closes the obj if it is a Closable.
|
||||
func Close(obj interface{}) error {
|
||||
if c, ok := obj.(Closable); ok {
|
||||
@@ -14,6 +19,15 @@ func Close(obj interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Interrupt calls Interrupt() if object implements Interruptible interface, or Close() if the object implements Closable interface.
|
||||
func Interrupt(obj interface{}) error {
|
||||
if c, ok := obj.(Interruptible); ok {
|
||||
c.Interrupt()
|
||||
return nil
|
||||
}
|
||||
return Close(obj)
|
||||
}
|
||||
|
||||
// Runnable is the interface for objects that can start to work and stop on demand.
|
||||
type Runnable interface {
|
||||
// Start starts the runnable object. Upon the method returning nil, the object begins to function properly.
|
||||
|
||||
Reference in New Issue
Block a user