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.

Questions on the proper use and handling of `done` callbacks

See original GitHub issue

Preface: trying to use choo on a project, and I’m somewhat confused, on several levels, about the proper usage of the done callback in effects and how it relates to the callback provided in the send method.

Here are my particular questions and areas where I’d appreciate some clarifications:

  1. In an effect handler, I understand the need to pass the done cb to subsequent send calls, to maintain the chain and allow errors to propagate upwards. But how should I handle the cb if I want to send 2+ actions from a single effect (e.g. I make an API call which returns data applicable to two separate models)? The following seems incorrect, but I’m not sure what the correct behavior should be:
myeffect: (state, data, send, done) => {
    ... make call to server ...
    send('foo:update', newFoo, done);
    send('bar:update', newBar, done);
}
  1. Aside from effects sending actions to reducers, we often send actions from views. Presumably the send provided to views is the same send provided to effects. So that implies that one could provide their own callback to be called once the sent action has completed. My question is if there’s is any common/encouraged use for this? I could imagine using it to update the html/UI if an error was encountered (which seems generally useful). But I could also imagine that such usage could present a race with the view being retriggered (because the state changed) and all sorts of unpredictable/undesired behavior occurring…

  2. Are there any examples of applications making use of the done callback in a non-trivial manner? It would be great to have something to reference to, and none of the examples in this repository seem to make use of it (there are cases of passing it an error, but as far as I can tell nothing acts on that error).

Thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:22 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
aknuds1commented, Mar 4, 2017

Well, classical Node style then.

1reaction
aknuds1commented, Mar 4, 2017

@jbucaran Your effect shouldn’t know if it’s being called by another asynchronous function though, should it? The caller would depend on knowing when the effect finishes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Javascript Interview Questions ( Promises ) - YouTube
JavascriptInterview #Javascript #FrontendInterviewJavascript Interview Questions on Async Javascript including Promises, Callback, ...
Read more >
JavaScript Callback Functions – What are Callbacks in JS and ...
Callbacks make sure that a function is not going to run before a task is completed but will run right after the task...
Read more >
Understanding the Event Loop, Callbacks, Promises, and ...
Now you know how the event loop uses the stack and queue to handle the execution order of code. The next task is...
Read more >
How is Callback handling implemented? - Stack Overflow
Windows API uses one callback which handles all events in a switch case. Other libraries use one callback per event class instead.
Read more >
Continued support for async tests with done callbacks #1893
For example, one may need to verify expectations in the subscription callback of an observable within a test that also needs to use...
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