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.

Make mergeMapConcurrently a public API

See original GitHub issue

Summary

While implementing a very simple photo library service, I have an observer containing the paths of photos available in the filesystem.

Given their path, I must enrich this data with metadata that I need to extract from the photos. If I just use a flatMap directly (which has a concurrency limit of Infinity) I crash my server:

photos(path.join(__dirname, '../pics'))
   .flatMap(enrichMetadata)
   .observe(f => console.log(f))

Searching for solutions and eventually at the internals of most I’ve found the implementations of flatMap and tried changing its Infinity to 1:

export function flatMap (f, stream) {
  return mergeMapConcurrently(f, 1, stream)
}

And all of the suddenly the metadata of the photos are being fetched one-by-one.

To make it work in my local setup, I’m importing it and using it directly:

const mergeMapConcurrently = require('most/lib/combinator/mergeConcurrently').mergeMapConcurrently

However, this is a very nasty short-term solution, so I’m suggesting either making mergeMapConcurrently public, or allow configuring concurrency value directly in flatMap.

Does it make sense?

I’m not sure what is the best approach here.

Versions

  • most.js: 1.7.2

btw, Most is awesome ❤️

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
TylorScommented, Nov 18, 2017

I agree we should make this API public 100%.

In your particular example of a concurrency of 1 you may want to look at switchLatest which is optimized specifically for a concurrency of 1.

0reactions
briancavaliercommented, Nov 20, 2017

Hey @pirelenito. I’m totally cool with making it public. Would you like to submit a PR to do that?

BTW, have you tried using map + mergeConcurrently? It’s not exactly the same, but may work, depending on your use case.

Cheers!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handle multiple API requests in Angular using mergeMap and ...
In this article, I will introduce two techniques to handle multiple requests in Angular by using mergeMap and forkJoin. In the real world, ......
Read more >
Is there a way to manage concurrency with RxJS?
You can use the mergeMap operator to perform the HTTP requests and to flatten the responses into the composed observable.
Read more >
Change "concurrent" value dynamically in mergeMap operator
My use-case is to let the end-users, play with the number of concurrent API-Fetch calls to be made dynamically.. just as a typical...
Read more >
Avoid Losing All Data in mergeMap RXJS Operator When ...
I fetch data of 5 users: A, B, C, D, and E in parallel using the mergeMap operator. API call made to fetch...
Read more >
3 Ways To Make Multiple HTTP Requests Using RxJS
We can use forkJoin to make multiple parallel HTTP requests. forkJoin will wait for all of the observables to complete, then emit 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