What is the best way to yield
until success of a Promise
using the js-csp
library?
For example:
import * as csp from 'js-csp'
const goRoutine = function*()
{
while (true)
{
const payload = yield csp.take(CHANNELS.SAVE_TO_SERVER);
yield api.save(payload); // returns promise
console.log("saved"); // should log after the promise was successful
}
}
csp.go(goRoutine);
This is possible to do using the co
library (see this answer) and was hoping that similar functionality would be available in js-csp
. If not, what is the ideal way to do this?
Normally we can do this by calling it.next(result)
on our generator when the Promise
has succeeded, but I don't see any way to gain access to this iterator from within our CSP 'go routine' in order to do this.