Skip to content

A library for arranging a huge amount of requests in one request.

License

Notifications You must be signed in to change notification settings

timzhong2000/nagle-request

Repository files navigation

English | 简体中文

Nagle Request

Nagle Request is a library for arranging a huge amount of requests in one request.

Overview

This project is inspired by Nagle Algorithm. When a huge amount of coroutine request the same api, the extra overhead can be avoided by arranging them in one request.

Features

  • Batch Size Limit - A request will be send immediately when the queue length reach the limit.

  • Optional Pluggable Cache - You can plugin any cache to provide flexable cache. You can also plugin JavaScript Map, and it can work fine. You can provide undefined and it will disable the cache.

Getting Started

Get student score in many coroutine but only create one http request.

const studentScore = new NagleRequest<string, number>({
  debounce: 50,
  maxRequestCount: 1000,
  batchRequestFn: async (batch: string[]) => {
    /** make a http request and return result*/
  },
  cacheFactory: Map,
});

// coroutine 1
await studentScore.request("stu_7mZTcjAO");

// coroutine 2
await studentScore.request("stu_oNAYIOH1");

// ... a lot of coroutine

License

Nagle Request is Apache 2.0 licensed.

About

A library for arranging a huge amount of requests in one request.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published