Skip to content
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

when will redux-saga migrate to async/await? #1373

Closed
anymost opened this Issue Mar 23, 2018 · 12 comments

Comments

Projects
None yet
7 participants
@anymost
Copy link

anymost commented Mar 23, 2018

As the title showed, I want to know when redux-saga will migrate to async/await, The generator function is too complicated to use.

@Andarist

This comment has been minimized.

Copy link
Member

Andarist commented Mar 23, 2018

No.

From the user perspective it is no different than async/await - effects are yielded and u can think of that as they would be "awaited".

From the library's (redux-saga) point of view async/await is to generators like a younger, dummy brother 😉 You can do much, much more with generators than with async/await.

Please also read this comment

@Andarist Andarist closed this Mar 23, 2018

@hoodwink73

This comment has been minimized.

Copy link
Contributor

hoodwink73 commented Apr 13, 2018

Hey @Andarist

Thanks for your efforts in Redux Saga.

Will you be open to adding a small section in the docs detailing why redux-saga uses generators over async/await and a disclaimer that we will not be using async/await?

There is a similar question raised in StackOverflow too.

@Andarist

This comment has been minimized.

Copy link
Member

Andarist commented Apr 14, 2018

I'm totally open for adding it, just not for adding it myself. Would you like to compile those 3 comments into a single short-ish section of the README?

@hoodwink73

This comment has been minimized.

Copy link
Contributor

hoodwink73 commented Apr 14, 2018

Absolutely. Will raise a PR.

@Andarist

This comment has been minimized.

Copy link
Member

Andarist commented Apr 14, 2018

Cool, thank you very much! 👍

@sincerekamal

This comment has been minimized.

Copy link

sincerekamal commented Jul 28, 2018

@Andarist Interested and eager to know what much more things redux-saga is doing with generators which is tough or impossible with async/await

@Andarist

This comment has been minimized.

Copy link
Member

Andarist commented Jul 29, 2018

@sincerekamal cancellation for starters - u cant cancel promises (which are ultimately created when calling async functions), but u can stop iterating through an iterator (u can even call its return method)

@antialias

This comment has been minimized.

Copy link

antialias commented Aug 16, 2018

u can even call its return method

return is a statement.

@alankar-anand

This comment has been minimized.

Copy link

alankar-anand commented Aug 21, 2018

I have used async await inside Redux saga. Here's the question on stackoverflow. Both can co-exist if someone wants to use it that way.

@Andarist

This comment has been minimized.

Copy link
Member

Andarist commented Aug 23, 2018

@antialias

It's also iterator's method 😉

function *saga() {}
var it = saga()
it.return()
@antialias

This comment has been minimized.

Copy link

antialias commented Aug 23, 2018

Cool! I'm apparently still learning about this stuff. Thanks @Andarist

@ceefour

This comment has been minimized.

Copy link

ceefour commented Jan 19, 2019

@Andarist I'm sorry to use this as a question, but I'd like to know how to do "await" with redux-saga ?

What I mean is, by dispatch()-ing an action, redux-saga will run it in background.

The problem is, I'd like the button (or whatever is the UI), to "await" the saga.

In essence:

try {
  await dispatchSomething();
  console.info("Yay it's done");
} catch (err) {
  console.error("Saga gave me error:", err);
}

Currently I'm doing something like this instead:

return new Promise((resolve, reject) => {
  dispatchSomething(resolve, reject);
}).then(res => console.info("Yay it's done"))
.catch(err => console.error("Saga gave me error:", err));

and the saga must call the given resolve / reject from the action, which seems to be weird...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.