1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-30 22:15:27 -05:00

Close outbound output stream properly. fix #1082

This commit is contained in:
Darien Raymond
2018-05-11 16:36:20 +02:00
parent 0301222e22
commit 8eb84a2025
5 changed files with 31 additions and 4 deletions

View File

@@ -0,0 +1,23 @@
package functions
import "v2ray.com/core/common"
// Task is a function that may return an error.
type Task func() error
// CloseOnSuccess returns a Task to run a follow task if pre-condition passes, otherwise the error in pre-condition is returned.
func CloseOnSuccess(pre func() error, followup Task) Task {
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)
}
}