{"version":3,"sources":["asynciterable/operators/throttle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,OAAO,qBAA+B,SAAQ,cAAuB;IAIzE,YAAY,MAA8B,EAAE,IAAY;QACtD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAoB;QAChD,cAAc,CAAC,MAAM,CAAC,CAAC;QACvB,IAAI,WAAW,CAAC;QAChB,IAAI,YAAY,CAAC;QACjB,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;YAC5D,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACzB,IAAI,CAAC,YAAY,IAAI,WAAW,GAAG,YAAY,GAAG,IAAI,CAAC,KAAK,EAAE;gBAC5D,YAAY,GAAG,WAAW,CAAC;gBAC3B,MAAM,IAAI,CAAC;aACZ;SACF;IACH,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAU,IAAY;IAC5C,OAAO,SAAS,wBAAwB,CACtC,MAA8B;QAE9B,OAAO,IAAI,qBAAqB,CAAU,MAAM,EAAE,IAAI,CAAC,CAAC;IAC1D,CAAC,CAAC;AACJ,CAAC","file":"throttle.js","sourcesContent":["import { AsyncIterableX } from '../asynciterablex';\nimport { MonoTypeOperatorAsyncFunction } from '../../interfaces';\nimport { wrapWithAbort } from './withabort';\nimport { throwIfAborted } from '../../aborterror';\n\nexport class ThrottleAsyncIterable<TSource> extends AsyncIterableX<TSource> {\n  private _source: AsyncIterable<TSource>;\n  private _time: number;\n\n  constructor(source: AsyncIterable<TSource>, time: number) {\n    super();\n    this._source = source;\n    this._time = time;\n  }\n\n  async *[Symbol.asyncIterator](signal?: AbortSignal) {\n    throwIfAborted(signal);\n    let currentTime;\n    let previousTime;\n    for await (const item of wrapWithAbort(this._source, signal)) {\n      currentTime = Date.now();\n      if (!previousTime || currentTime - previousTime > this._time) {\n        previousTime = currentTime;\n        yield item;\n      }\n    }\n  }\n}\n\n/**\n * Throttles the source async-iterable sequence so that it doesn't emit more than one value during the given timeframe.\n *\n * @export\n * @template TSource The type of elements in the source sequence.\n * @param {number} time The time in milliseconds to throttle the source sequence.\n * @returns {MonoTypeOperatorAsyncFunction<TSource>} The source sequence throttled by the given timeframe.\n */\nexport function throttle<TSource>(time: number): MonoTypeOperatorAsyncFunction<TSource> {\n  return function throttleOperatorFunction(\n    source: AsyncIterable<TSource>\n  ): AsyncIterableX<TSource> {\n    return new ThrottleAsyncIterable<TSource>(source, time);\n  };\n}\n"]}