-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
suggestion: AsyncIterable.iterAsync/iterPromise function #56
Comments
I am not familiar with the But would change the code to be enough? I just added I didn't test the code, and I don't know if JavaScript allows to have an await here, but I don't see why not. /// Iterates AsyncIterable. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of
let iter (action: CancellationToken -> 'T -> unit) (iterable: JS.AsyncIterable<'T>): JS.Promise<unit> =
let token = CancellationToken()
emitJsExpr () """(async () => {
for await (const value of iterable) {
try {
await action(token, value)
} catch (err) {
if (err instanceof token.constructor) {
break;
}
throw(err);
}
}
})()""" The other solution would probably be to create a |
I was looking at this issue again and I don't exactly see what your last message was trying to point to. Could you please try to explain what is missing between |
At the call site, (iterable) => iter((_arg, x) => {
new Promise(resolve => setTimeout(resolve, 1000));
}, iterable); Whereas in (iterable) => iter2((_arg, x) => (new Promise(resolve => setTimeout(resolve, 1000))), iterable); |
The
AsyncIteratable.iter
function doesn't allow processing an item using a promise. It would be convenient to have another helper that adds an await here:fable-promise/src/AsyncIterable.fs
Line 49 in b40f8cd
The text was updated successfully, but these errors were encountered: