Socket
Book a DemoInstallSign in
Socket

create-merged-request

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-merged-request

Merge scattered requests into one, distribute corresponding result to requestor.

1.0.0
latest
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

create-merged-request

Merge scattered requests into one, distribute corresponding result to requestor.

Install

npm i create-merged-request rxjs # Please note that rxjs is peer dependency of it

Usage

import { createMergedRequest } from 'create-merged-request'

// `string` is user id
// `User[]` is the response data type that `createRequest` resolves
// `User` is the data type that `createResponse` returns
const mergedRequest = createMergedRequest<string, User[], User>({
  thresholdMs: 0, // time threshold to merged request into one request
  createRequest(ids) {
    return fetchUsers(ids) // type: (ids: string[]) => Promise<User[]>
  },
  createResponse(id, users) {
    return users.find((user) => user.id === id)! // type: User
  }
})

// Only 1 `fetchUsers` will be called
mergedRequest(userId1).then((user) => console.log(user))
mergedRequest(userId2).then((user) => console.log(user))
mergedRequest(userId3).then((user) => console.log(user))

FAQs

Package last updated on 17 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.