2

Our team is starting to learn fp-ts, and we are starting with some basic async examples (mostly pulled from here). Running a set of Tasks in sequence is great, and it looks like array.sequence(task)(tasks) The question is, what is the idiomatic way to restrict concurrency when executing parallel Tasks in fp-ts? For example, Promise.map (in bluebird) allows you to set a concurrency limit like {concurrency: 4}.

One solution might be to split the array into chunks, and then iterate the chunks, using sequence and flatMap. However, that would mean every Task in each chunk would have to complete before moving on to the next chunk - one long running task could hold up the whole operation.

There must be some abstraction that we're missing - we are all pretty new to FP, so hopefully someone here with more exp can help out.

Tim
  • 1,013
  • 1
  • 10
  • 16
  • 1
    Apparently the `Task` type of the fp-ts library doesn't support this. So you have to implement it yourself, probably with a queue of tasks. There is no general combinator for this issue in FP. –  May 10 '19 at 08:33
  • Thanks, that's good to know! – Tim May 10 '19 at 12:13

1 Answers1

2

I was able to find a resolution with the helpful folks over at the ts-fp git repo. Looks like wrapping p-map is the way to go

https://github.com/gcanti/fp-ts/issues/574#issuecomment-424658481

Tim
  • 1,013
  • 1
  • 10
  • 16