This should probably be implemented in a separated repository. I am looking for a package that will support something like:
const pKeyLimit = require('p-key-limit');
const limiter = pKeyLimit(1); // concurrency is 1
limit('k1', () => taskA()).then(result => console.log(`Task A Done: ${result}`));
limit('k2', () => taskB()).then(result => console.log(`Task B Done: ${result}`)); // different key (k2) - will run in parallel to taskA
limit('k1', () => taskC()).then(result => console.log(`Task C Done: ${result}`)); // same key (k1) - will start executing after taskA has finished (recall that concurrency is 1).
Obviously, this could be implemented by maintaining a Map of keys to p-limits. However, there should be some way to clean the map from p-limits that have finished (maybe by wrapping the function that is passed to the internal p-limit).
I will be happy to hear if something like that was already implemented!
This should probably be implemented in a separated repository. I am looking for a package that will support something like:
Obviously, this could be implemented by maintaining a Map of keys to p-limits. However, there should be some way to clean the map from p-limits that have finished (maybe by wrapping the function that is passed to the internal p-limit).
I will be happy to hear if something like that was already implemented!