Well, in Node.js or in Clojure...
I ran into a problem — all of the requests are relying on a task on the server. So they have to wait until the task is finished.
I got one solution from my friend — use promise to wrap the task and let others use yield to wait for that task. And my code is using Koa, it looks strange to create a Promise inside the generator functions.
Do you have any good ideas doing this, in JavaScript(Node 6.x), or in Clojure?
Promise is the right choice for now.
Promise.all([/* array of promises */])
.then(/* runs when all promises from the array are resolved */)
.catch(/* runs when any of the promises rejects */)
In the near future you have more options.
Marco Alka
Software Engineer, Technical Consultant & Mentor
As for Node.JS (I do not know Clojure):
Since you did not provide any source, I guess the best solution is to use promises. I do not know why you would use generator functions, though. Please elaborate.
Alternatively you could use a callback, but Promises are more flexible imo.