3 ms·
Talking about coroutines, how do you do a synonym of async/await + Promise.all + cancellation token? In a microservice world, I habe to send a request to 6 mic
by hyeomans 7y ago
Talking about coroutines, how do you do a synonym of async/await + Promise.all + cancellation token?
In a microservice world, I habe to send a request to 6 microservices and I want to do them concurrently not sequentially
- omani 7y agouse zeromq
- nine_k 7y agoSpin several goroutines, do a `select` on them. It's right in the Tour of Go. Cancellation tokens are harder, though.
- tonyarkles 7y agoIt’s been a while since I’ve been writing Go, but wasn’t that nominally what the Context objects were supposed to be for? I think they were introduced a bit late in the game, but APIs that supported them handled cancellation well (if I’m remembering right)
- owaislone 7y agoContext would be passed to each go-routines for cancellation but the pattern would be the same as OP's suggestion. I'd say a set of go-routines and a sync.WaitGroup would probably be a better pattern for this use case. Routines + select is more useful for listening on incoming data than concurrently sending out bytes.