2018-05-11 16:36:20 +02:00
|
|
|
package functions
|
|
|
|
|
|
|
|
import "v2ray.com/core/common"
|
|
|
|
|
|
|
|
// Task is a function that may return an error.
|
|
|
|
type Task func() error
|
|
|
|
|
2018-05-27 11:42:01 +02:00
|
|
|
// OnSuccess returns a Task to run a follow task if pre-condition passes, otherwise the error in pre-condition is returned.
|
|
|
|
func OnSuccess(pre func() error, followup Task) Task {
|
2018-05-11 16:36:20 +02:00
|
|
|
return func() error {
|
|
|
|
if err := pre(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return followup()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close returns a Task to close the object.
|
|
|
|
func Close(obj interface{}) Task {
|
|
|
|
return func() error {
|
|
|
|
return common.Close(obj)
|
|
|
|
}
|
|
|
|
}
|