-
Notifications
You must be signed in to change notification settings - Fork 25
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
Add opt-in to make Promises
operations
#812
Comments
More generally, how does Effection mix with existing code bases that use promises or async functions, does it work at all? |
@davidbrochart It's really easy to mix Effection code with Async code and vice-versa. In fact, it's a design goal. In most cases, you can use import { call, useAbortSignal } from 'effection';
function* search(q) {
let signal = yield* useAbortSignal();
let response = yield* call(() => fetch(`https://google.com?q=${q}`, { signal }));
return yield* call(() => response.text());
} (Notice how we did not need to bother with the abort controller, as this is taken care of by structured concurrency) It is possible by adding import { useAbortSignal } from 'effection';
function* search(q) {
let signal = yield* useAbortSignal();
let response = yield* fetch(`https://google.com?q=${q}`, { signal });
return yield* response.text();
} We do this in the Effection test suite itself in order to make testing with promises even more concise. While we would not want to do this by default, we might want to make it available as an opt-in for those who are ok with it. For more information about the interoperation between the structured concurrency and async worlds see the Async Rosetta Stone |
Thanks a lot for the details @cowboyd, very interesting! |
Having to wrap every promise or async function in
call()
is doable, but a pain, and it stretches the promise that Effection makes of being a very straightforward translation fromasync/await
.We should have a module that makes promise an operation:
Or something like that.
The text was updated successfully, but these errors were encountered: