create-merged-request
Merge scattered requests into one, distribute corresponding result to requestor.
Install
npm i create-merged-request rxjs
Usage
import { createMergedRequest } from 'create-merged-request'
const mergedRequest = createMergedRequest<string, User[], User>({
thresholdMs: 0,
createRequest(ids) {
return fetchUsers(ids)
},
createResponse(id, users) {
return users.find((user) => user.id === id)!
}
})
mergedRequest(userId1).then((user) => console.log(user))
mergedRequest(userId2).then((user) => console.log(user))
mergedRequest(userId3).then((user) => console.log(user))