mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-06 13:27:39 +03:00
Add ctx to task.Any
This commit is contained in:
parent
6a0987c52a
commit
04e100e91a
2 changed files with 6 additions and 6 deletions
|
@ -283,18 +283,18 @@ func CopyPacketWithPoolTimeout(dest N.PacketWriter, src N.TimeoutPacketReader, t
|
||||||
|
|
||||||
func CopyPacketConn(ctx context.Context, conn N.PacketConn, dest N.PacketConn) error {
|
func CopyPacketConn(ctx context.Context, conn N.PacketConn, dest N.PacketConn) error {
|
||||||
defer common.Close(conn, dest)
|
defer common.Close(conn, dest)
|
||||||
return task.Any(ctx, func() error {
|
return task.Any(ctx, func(ctx context.Context) error {
|
||||||
return common.Error(CopyPacket(dest, conn))
|
return common.Error(CopyPacket(dest, conn))
|
||||||
}, func() error {
|
}, func(ctx context.Context) error {
|
||||||
return common.Error(CopyPacket(conn, dest))
|
return common.Error(CopyPacket(conn, dest))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func CopyPacketConnTimeout(ctx context.Context, conn N.PacketConn, dest N.PacketConn, timeout time.Duration) error {
|
func CopyPacketConnTimeout(ctx context.Context, conn N.PacketConn, dest N.PacketConn, timeout time.Duration) error {
|
||||||
defer common.Close(conn, dest)
|
defer common.Close(conn, dest)
|
||||||
return task.Any(ctx, func() error {
|
return task.Any(ctx, func(ctx context.Context) error {
|
||||||
return common.Error(CopyPacketTimeout(dest, conn, timeout))
|
return common.Error(CopyPacketTimeout(dest, conn, timeout))
|
||||||
}, func() error {
|
}, func(ctx context.Context) error {
|
||||||
return common.Error(CopyPacketTimeout(conn, dest, timeout))
|
return common.Error(CopyPacketTimeout(conn, dest, timeout))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,13 +34,13 @@ func Run(ctx context.Context, tasks ...func() error) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
//goland:noinspection GoVetLostCancel
|
//goland:noinspection GoVetLostCancel
|
||||||
func Any(ctx context.Context, tasks ...func() error) error {
|
func Any(ctx context.Context, tasks ...func(ctx context.Context) error) error {
|
||||||
runtimeCtx, cancel := context.WithCancel(ctx)
|
runtimeCtx, cancel := context.WithCancel(ctx)
|
||||||
var retErr error
|
var retErr error
|
||||||
for _, task := range tasks {
|
for _, task := range tasks {
|
||||||
currentTask := task
|
currentTask := task
|
||||||
go func() {
|
go func() {
|
||||||
if err := currentTask(); err != nil {
|
if err := currentTask(runtimeCtx); err != nil {
|
||||||
retErr = err
|
retErr = err
|
||||||
}
|
}
|
||||||
cancel()
|
cancel()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue