Skip to content

Merge asynchronous calls with other duplicate calls in progress

License

Notifications You must be signed in to change notification settings

mikecote/async-merge-calls

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

async-merge-calls

Merge asynchronous calls with other duplicate calls in progress

Example

Below is an example of how calls will be merged to reduce the number of times redis gets called.

Redis will be called once to get 1 and another for 2 while each callback will be properly called with the result from redis.

Redis will be called once again when no existing calls are in progress for a given id.

const mergeCalls = require('async-merge-calls');

function readFromRedis(id, done) {
	redis.get(id, done);
}

function printResult(err, result) {
	if (err) throw err;
	console.log(result);
}

const readFromRedisAggregated = mergeCalls(readFromRedis);
readFromRedisAggregated(1, printResult);
readFromRedisAggregated(1, printResult);
readFromRedisAggregated(2, printResult);

readFromRedis will be called once with 1 and another time with 2.

About

Merge asynchronous calls with other duplicate calls in progress

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published