functions.go 536 B

1234567891011121314151617181920212223
  1. package functions
  2. import "v2ray.com/core/common"
  3. // Task is a function that may return an error.
  4. type Task func() error
  5. // OnSuccess returns a Task to run a follow task if pre-condition passes, otherwise the error in pre-condition is returned.
  6. func OnSuccess(pre func() error, followup Task) Task {
  7. return func() error {
  8. if err := pre(); err != nil {
  9. return err
  10. }
  11. return followup()
  12. }
  13. }
  14. // Close returns a Task to close the object.
  15. func Close(obj interface{}) Task {
  16. return func() error {
  17. return common.Close(obj)
  18. }
  19. }