1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-26 03:55:26 -05:00

better way to run tasks in parallel

This commit is contained in:
Darien Raymond
2018-04-11 16:45:09 +02:00
parent 9d7f43a299
commit 0caf92726b
11 changed files with 79 additions and 90 deletions

View File

@@ -75,7 +75,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
return newError("failed to dispatch request").Base(err)
}
requestDone := signal.ExecuteAsync(func() error {
requestDone := func() error {
defer inboundRay.InboundInput().Close()
defer timer.SetTimeout(d.policy().Timeouts.DownlinkOnly)
@@ -86,9 +86,9 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
}
return nil
})
}
responseDone := signal.ExecuteAsync(func() error {
responseDone := func() error {
defer timer.SetTimeout(d.policy().Timeouts.UplinkOnly)
var writer buf.Writer
@@ -113,9 +113,9 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
}
return nil
})
}
if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
if err := signal.ExecuteParallel(ctx, requestDone, responseDone); err != nil {
inboundRay.InboundInput().CloseError()
inboundRay.InboundOutput().CloseError()
return newError("connection ends").Base(err)