1
0
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:
Darien Raymond
2018-12-31 21:25:10 +01:00
parent d35c407419
commit 3de8389361
21 changed files with 66 additions and 69 deletions

View File

@@ -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.