question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handling saga IO from within callbacks

See original GitHub issue

Yielding a call to a function that is using a callback to run its post execution behavior: yield apply(someObject, someFunction)

Seems I can’t yield put from someFunction since the callback isn’t a generator. How can I dispatch an action from that callback?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
yelouaficommented, Jan 20, 2016

addEventListener calls its callback with the event as a first parameter. cps’s callback is called with the event as a first argument by addEventListener, since cps expects an error first argument. it treats the event as an error.

I’d opt for your first solution but would remove the event listener after the promise is resolved

const waitForEvent = (elm, eventType) => {
  return new Promise(resolve => {
    const cb = e => {
      resolve(e)
      elm.removeEventListener(eventType, cb)
    }
    elm.addEventListener(eventType, cb)
  })
}
0reactions
floydwchcommented, Jan 26, 2016

Hi @yelouafi !

Thanks for your awesome work, but I have a question here: how to remove listeners in the automatically canceled race effects?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to "yield put" in redux-saga within a callback?
One possible solution, as you already mentioned, is to use channels . Here is an example that should work in your case:
Read more >
API Reference - Redux-Saga
Spawns a saga on each action dispatched to the Store that matches pattern . After spawning a task once, it blocks until spawned...
Read more >
Handle Side-Effects With Redux-Saga - Frontend - Scalac.io
Project showing how to move all side-effects away from action-creators. In a way that makes them as clean as possible with Redux-Saga.
Read more >
3.10. Attributes and Callbacks — SAGA 1.18.0 documentation
All objects using the Attribute Interface allow to register a callback for any changes of its attributes, such as 'state' and 'state_detail'. Those...
Read more >
Redux-Saga race conditions - Medium
Asynchronous program flow is a well known feature in JavaScript environments. All of us extensively use callbacks, Promises at the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found