diff --git a/core/commands/dht.go b/core/commands/dht.go index 27f0cee20..89e3bffb7 100644 --- a/core/commands/dht.go +++ b/core/commands/dht.go @@ -174,9 +174,6 @@ var findProvidersDhtCmd = &cmds.Command{ return } - outChan := make(chan interface{}) - res.SetOutput((<-chan interface{})(outChan)) - events := make(chan *notif.QueryEvent) ctx := notif.RegisterForQueryEvents(req.Context(), events) @@ -186,6 +183,9 @@ var findProvidersDhtCmd = &cmds.Command{ return } + outChan := make(chan interface{}) + res.SetOutput((<-chan interface{})(outChan)) + pchan := dht.FindProvidersAsync(ctx, c, numProviders) go func() { defer close(outChan) @@ -535,18 +535,18 @@ Different key types can specify other 'best' rules. return } - outChan := make(chan interface{}) - res.SetOutput((<-chan interface{})(outChan)) - - events := make(chan *notif.QueryEvent) - ctx := notif.RegisterForQueryEvents(req.Context(), events) - dhtkey, err := escapeDhtKey(req.Arguments()[0]) if err != nil { res.SetError(err, cmdkit.ErrNormal) return } + outChan := make(chan interface{}) + res.SetOutput((<-chan interface{})(outChan)) + + events := make(chan *notif.QueryEvent) + ctx := notif.RegisterForQueryEvents(req.Context(), events) + go func() { defer close(outChan) for e := range events { @@ -650,9 +650,6 @@ NOTE: A value may not exceed 2048 bytes. return } - outChan := make(chan interface{}) - res.SetOutput((<-chan interface{})(outChan)) - events := make(chan *notif.QueryEvent) ctx := notif.RegisterForQueryEvents(req.Context(), events) @@ -662,6 +659,9 @@ NOTE: A value may not exceed 2048 bytes. return } + outChan := make(chan interface{}) + res.SetOutput((<-chan interface{})(outChan)) + data := req.Arguments()[1] go func() {