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.

Returning Promises from Highland methods

See original GitHub issue

My workflow looks somewhat like this:

    .map(function(item){ return doAsyncThing(item); })
    .each(function(item){ console.log(item); });

… where doAsyncThing returns a Bluebird promise. I had expected for Highland to await resolution of the promise and pass the final resolution value to the .each call (much like Bluebird’s own .map and .each), but instead my .each method is receiving the Promise objects themselves.

Is it possible to make Highland behave like I’m trying to accomplish, without having to manually .then in the .each handler, as that would defeat the point of doing things this way?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:30

github_iconTop GitHub Comments

apaleslimghostcommented, Apr 27, 2015

You can use flatMap and wrap the promise in a stream:

    .flatMap(function(item){ return _(doAsyncThing(item)); })
    .each(function(item){ console.log(item); });
svozzacommented, Apr 27, 2015

Ha. Your answer is actually better because it explains why it works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

These methods return Stream objects, not Arrays, so you can chain together ... Promise - Accepts an ES6 / jQuery style promise and...
Read more >
How to handle promise rejection when creating a highland ...
How can I only work on successful promises streams and ignore the failing ones using highland? How am I supposed to handle the...
Read more >
Promise - JavaScript - MDN Web Docs
Returns a new Promise object that is resolved with the given value. If the value is a thenable (i.e. has a then method),...
Read more >
Coming from Other Libraries - Bluebird JS
Bluebird treats jQuery deferreds and promises interchangeably. Wherever you can take a promise or return a promise, you can take or return a...
Read more >
Dallas CAD – Official Site
We anticipate the return of our full functioning website sometime in early 2023. The authorities are aware of our ransomware case and we...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found