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
btw, Most is awesome ❤️
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
flatMapdirectly (which has a concurrency limit ofInfinity) I crash my server:Searching for solutions and eventually at the internals of
mostI've found the implementations of flatMap and tried changing itsInfinityto1: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:
However, this is a very nasty short-term solution, so I'm suggesting either making
mergeMapConcurrentlypublic, or allow configuringconcurrencyvalue directly inflatMap.Does it make sense?
I'm not sure what is the best approach here.
Versions
btw, Most is awesome ❤️