Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ConcurrentMerger

单任务队列

  1. 被修饰的函数,同一时间只允许执行一个异步请求。
  2. 在异步请求完成之前,其他调用请求会被进入队列。
  3. 异步请求完成之后,队列中的请求会被释放,共用同一个结果。

使用场景:高并发秒杀场景、刷新登录态场景等

Hierarchy

  • ConcurrentMerger

Index

Constructors

constructor

  • new ConcurrentMerger(__namedParameters: { name: string; queueMaxLength: number }): ConcurrentMerger

Properties

Private locked

locked: boolean = false

name

name: string = "unnamed"

Private queue

queue: Array<any> = []

queueMaxLength

queueMaxLength: number = 100

Methods

Private addJob

  • addJob(job: Array<any>): void

Private consumeAllAsFail

  • consumeAllAsFail(error: any): void

Private consumeAllAsSuccess

  • consumeAllAsSuccess(result: any): void

proxy

  • proxy(originMethods: (...any: any[]) => Promise<any>): (Anonymous function)
  • Parameters

    • originMethods: (...any: any[]) => Promise<any>
        • (...any: any[]): Promise<any>
        • Parameters

          • Rest ...any: any[]

          Returns Promise<any>

    Returns (Anonymous function)

Generated using TypeDoc