index.es6.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. import { JSONExt, PromiseDelegate } from '@lumino/coreutils';
  2. import { Signal } from '@lumino/signaling';
  3. /*! *****************************************************************************
  4. Copyright (c) Microsoft Corporation. All rights reserved.
  5. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  6. this file except in compliance with the License. You may obtain a copy of the
  7. License at http://www.apache.org/licenses/LICENSE-2.0
  8. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  9. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  10. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  11. MERCHANTABLITY OR NON-INFRINGEMENT.
  12. See the Apache Version 2.0 License for specific language governing permissions
  13. and limitations under the License.
  14. ***************************************************************************** */
  15. /* global Reflect, Promise */
  16. var extendStatics = function(d, b) {
  17. extendStatics = Object.setPrototypeOf ||
  18. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  19. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  20. return extendStatics(d, b);
  21. };
  22. function __extends(d, b) {
  23. extendStatics(d, b);
  24. function __() { this.constructor = d; }
  25. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  26. }
  27. var __assign = function() {
  28. __assign = Object.assign || function __assign(t) {
  29. for (var s, i = 1, n = arguments.length; i < n; i++) {
  30. s = arguments[i];
  31. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  32. }
  33. return t;
  34. };
  35. return __assign.apply(this, arguments);
  36. };
  37. function __awaiter(thisArg, _arguments, P, generator) {
  38. return new (P || (P = Promise))(function (resolve, reject) {
  39. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  40. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  41. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  42. step((generator = generator.apply(thisArg, _arguments || [])).next());
  43. });
  44. }
  45. function __generator(thisArg, body) {
  46. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  47. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  48. function verb(n) { return function (v) { return step([n, v]); }; }
  49. function step(op) {
  50. if (f) throw new TypeError("Generator is already executing.");
  51. while (_) try {
  52. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  53. if (y = 0, t) op = [op[0] & 2, t.value];
  54. switch (op[0]) {
  55. case 0: case 1: t = op; break;
  56. case 4: _.label++; return { value: op[1], done: false };
  57. case 5: _.label++; y = op[1]; op = [0]; continue;
  58. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  59. default:
  60. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  61. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  62. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  63. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  64. if (t[2]) _.ops.pop();
  65. _.trys.pop(); continue;
  66. }
  67. op = body.call(thisArg, _);
  68. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  69. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  70. }
  71. }
  72. // Copyright (c) Jupyter Development Team.
  73. /**
  74. * A function to defer an action immediately.
  75. */
  76. var defer = typeof requestAnimationFrame === 'function'
  77. ? requestAnimationFrame
  78. : setImmediate;
  79. /**
  80. * A function to cancel a deferred action.
  81. */
  82. var cancel = typeof cancelAnimationFrame === 'function'
  83. ? cancelAnimationFrame
  84. : clearImmediate;
  85. /**
  86. * A class that wraps an asynchronous function to poll at a regular interval
  87. * with exponential increases to the interval length if the poll fails.
  88. *
  89. * @typeparam T - The resolved type of the factory's promises.
  90. * Defaults to `any`.
  91. *
  92. * @typeparam U - The rejected type of the factory's promises.
  93. * Defaults to `any`.
  94. *
  95. * @typeparam V - An optional type to extend the phases supported by a poll.
  96. * Defaults to `standby`, which already exists in the `Phase` type.
  97. */
  98. var Poll = /** @class */ (function () {
  99. /**
  100. * Instantiate a new poll with exponential backoff in case of failure.
  101. *
  102. * @param options - The poll instantiation options.
  103. */
  104. function Poll(options) {
  105. var _this = this;
  106. this._disposed = new Signal(this);
  107. this._tick = new PromiseDelegate();
  108. this._ticked = new Signal(this);
  109. this._timeout = -1;
  110. this._factory = options.factory;
  111. this._standby = options.standby || Private.DEFAULT_STANDBY;
  112. this._state = __assign(__assign({}, Private.DEFAULT_STATE), { timestamp: new Date().getTime() });
  113. // Normalize poll frequency `max` to be the greater of
  114. // default `max`, `options.frequency.max`, or `options.frequency.interval`.
  115. var frequency = options.frequency || {};
  116. var max = Math.max(frequency.interval || 0, frequency.max || 0, Private.DEFAULT_FREQUENCY.max);
  117. this.frequency = __assign(__assign(__assign({}, Private.DEFAULT_FREQUENCY), frequency), { max: max });
  118. this.name = options.name || Private.DEFAULT_NAME;
  119. if ('auto' in options ? options.auto : true) {
  120. defer(function () { return void _this.start(); });
  121. }
  122. }
  123. Object.defineProperty(Poll.prototype, "disposed", {
  124. /**
  125. * A signal emitted when the poll is disposed.
  126. */
  127. get: function () {
  128. return this._disposed;
  129. },
  130. enumerable: true,
  131. configurable: true
  132. });
  133. Object.defineProperty(Poll.prototype, "frequency", {
  134. /**
  135. * The polling frequency parameters.
  136. */
  137. get: function () {
  138. return this._frequency;
  139. },
  140. set: function (frequency) {
  141. if (this.isDisposed || JSONExt.deepEqual(frequency, this.frequency || {})) {
  142. return;
  143. }
  144. var backoff = frequency.backoff, interval = frequency.interval, max = frequency.max;
  145. interval = Math.round(interval);
  146. max = Math.round(max);
  147. if (typeof backoff === 'number' && backoff < 1) {
  148. throw new Error('Poll backoff growth factor must be at least 1');
  149. }
  150. if ((interval < 0 || interval > max) && interval !== Poll.NEVER) {
  151. throw new Error('Poll interval must be between 0 and max');
  152. }
  153. if (max > Poll.MAX_INTERVAL && max !== Poll.NEVER) {
  154. throw new Error("Max interval must be less than " + Poll.MAX_INTERVAL);
  155. }
  156. this._frequency = { backoff: backoff, interval: interval, max: max };
  157. },
  158. enumerable: true,
  159. configurable: true
  160. });
  161. Object.defineProperty(Poll.prototype, "isDisposed", {
  162. /**
  163. * Whether the poll is disposed.
  164. */
  165. get: function () {
  166. return this.state.phase === 'disposed';
  167. },
  168. enumerable: true,
  169. configurable: true
  170. });
  171. Object.defineProperty(Poll.prototype, "standby", {
  172. /**
  173. * Indicates when the poll switches to standby.
  174. */
  175. get: function () {
  176. return this._standby;
  177. },
  178. set: function (standby) {
  179. if (this.isDisposed || this.standby === standby) {
  180. return;
  181. }
  182. this._standby = standby;
  183. },
  184. enumerable: true,
  185. configurable: true
  186. });
  187. Object.defineProperty(Poll.prototype, "state", {
  188. /**
  189. * The poll state, which is the content of the current poll tick.
  190. */
  191. get: function () {
  192. return this._state;
  193. },
  194. enumerable: true,
  195. configurable: true
  196. });
  197. Object.defineProperty(Poll.prototype, "tick", {
  198. /**
  199. * A promise that resolves when the poll next ticks.
  200. */
  201. get: function () {
  202. return this._tick.promise;
  203. },
  204. enumerable: true,
  205. configurable: true
  206. });
  207. Object.defineProperty(Poll.prototype, "ticked", {
  208. /**
  209. * A signal emitted when the poll ticks and fires off a new request.
  210. */
  211. get: function () {
  212. return this._ticked;
  213. },
  214. enumerable: true,
  215. configurable: true
  216. });
  217. /**
  218. * Dispose the poll.
  219. */
  220. Poll.prototype.dispose = function () {
  221. if (this.isDisposed) {
  222. return;
  223. }
  224. this._state = __assign(__assign({}, Private.DISPOSED_STATE), { timestamp: new Date().getTime() });
  225. this._tick.promise.catch(function (_) { return undefined; });
  226. this._tick.reject(new Error("Poll (" + this.name + ") is disposed."));
  227. this._disposed.emit(undefined);
  228. Signal.clearData(this);
  229. };
  230. /**
  231. * Refreshes the poll. Schedules `refreshed` tick if necessary.
  232. *
  233. * @returns A promise that resolves after tick is scheduled and never rejects.
  234. *
  235. * #### Notes
  236. * The returned promise resolves after the tick is scheduled, but before
  237. * the polling action is run. To wait until after the poll action executes,
  238. * await the `poll.tick` promise: `await poll.refresh(); await poll.tick;`
  239. */
  240. Poll.prototype.refresh = function () {
  241. return this.schedule({
  242. cancel: function (_a) {
  243. var phase = _a.phase;
  244. return phase === 'refreshed';
  245. },
  246. interval: Poll.IMMEDIATE,
  247. phase: 'refreshed'
  248. });
  249. };
  250. /**
  251. * Schedule the next poll tick.
  252. *
  253. * @param next - The next poll state data to schedule. Defaults to standby.
  254. *
  255. * @param next.cancel - Cancels state transition if function returns `true`.
  256. *
  257. * @returns A promise that resolves when the next poll state is active.
  258. *
  259. * #### Notes
  260. * This method is not meant to be invoked by user code typically. It is public
  261. * to allow poll instances to be composed into classes that schedule ticks.
  262. */
  263. Poll.prototype.schedule = function (next) {
  264. if (next === void 0) { next = {}; }
  265. return __awaiter(this, void 0, void 0, function () {
  266. var last, pending, scheduled, state, execute;
  267. var _this = this;
  268. return __generator(this, function (_a) {
  269. switch (_a.label) {
  270. case 0:
  271. if (this.isDisposed) {
  272. return [2 /*return*/];
  273. }
  274. // Check if the phase transition should be canceled.
  275. if (next.cancel && next.cancel(this.state)) {
  276. return [2 /*return*/];
  277. }
  278. last = this.state;
  279. pending = this._tick;
  280. scheduled = new PromiseDelegate();
  281. state = __assign({ interval: this.frequency.interval, payload: null, phase: 'standby', timestamp: new Date().getTime() }, next);
  282. this._state = state;
  283. this._tick = scheduled;
  284. // Clear the schedule if possible.
  285. if (last.interval === Poll.IMMEDIATE) {
  286. cancel(this._timeout);
  287. }
  288. else {
  289. clearTimeout(this._timeout);
  290. }
  291. // Emit ticked signal, resolve pending promise, and await its settlement.
  292. this._ticked.emit(this.state);
  293. pending.resolve(this);
  294. return [4 /*yield*/, pending.promise];
  295. case 1:
  296. _a.sent();
  297. execute = function () {
  298. if (_this.isDisposed || _this.tick !== scheduled.promise) {
  299. return;
  300. }
  301. _this._execute();
  302. };
  303. this._timeout =
  304. state.interval === Poll.IMMEDIATE
  305. ? defer(execute)
  306. : state.interval === Poll.NEVER
  307. ? -1
  308. : setTimeout(execute, state.interval);
  309. return [2 /*return*/];
  310. }
  311. });
  312. });
  313. };
  314. /**
  315. * Starts the poll. Schedules `started` tick if necessary.
  316. *
  317. * @returns A promise that resolves after tick is scheduled and never rejects.
  318. */
  319. Poll.prototype.start = function () {
  320. return this.schedule({
  321. cancel: function (_a) {
  322. var phase = _a.phase;
  323. return phase !== 'constructed' && phase !== 'standby' && phase !== 'stopped';
  324. },
  325. interval: Poll.IMMEDIATE,
  326. phase: 'started'
  327. });
  328. };
  329. /**
  330. * Stops the poll. Schedules `stopped` tick if necessary.
  331. *
  332. * @returns A promise that resolves after tick is scheduled and never rejects.
  333. */
  334. Poll.prototype.stop = function () {
  335. return this.schedule({
  336. cancel: function (_a) {
  337. var phase = _a.phase;
  338. return phase === 'stopped';
  339. },
  340. interval: Poll.NEVER,
  341. phase: 'stopped'
  342. });
  343. };
  344. /**
  345. * Execute a new poll factory promise or stand by if necessary.
  346. */
  347. Poll.prototype._execute = function () {
  348. var _this = this;
  349. var standby = typeof this.standby === 'function' ? this.standby() : this.standby;
  350. standby =
  351. standby === 'never'
  352. ? false
  353. : standby === 'when-hidden'
  354. ? !!(typeof document !== 'undefined' && document && document.hidden)
  355. : standby;
  356. // If in standby mode schedule next tick without calling the factory.
  357. if (standby) {
  358. void this.schedule();
  359. return;
  360. }
  361. var pending = this.tick;
  362. this._factory(this.state)
  363. .then(function (resolved) {
  364. if (_this.isDisposed || _this.tick !== pending) {
  365. return;
  366. }
  367. void _this.schedule({
  368. payload: resolved,
  369. phase: _this.state.phase === 'rejected' ? 'reconnected' : 'resolved'
  370. });
  371. })
  372. .catch(function (rejected) {
  373. if (_this.isDisposed || _this.tick !== pending) {
  374. return;
  375. }
  376. void _this.schedule({
  377. interval: Private.sleep(_this.frequency, _this.state),
  378. payload: rejected,
  379. phase: 'rejected'
  380. });
  381. });
  382. };
  383. return Poll;
  384. }());
  385. /**
  386. * A namespace for `Poll` types, interfaces, and statics.
  387. */
  388. (function (Poll) {
  389. /**
  390. * An interval value that indicates the poll should tick immediately.
  391. */
  392. Poll.IMMEDIATE = 0;
  393. /**
  394. * Delays are 32-bit integers in many browsers so intervals need to be capped.
  395. *
  396. * #### Notes
  397. * https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout#Maximum_delay_value
  398. */
  399. Poll.MAX_INTERVAL = 2147483647;
  400. /**
  401. * An interval value that indicates the poll should never tick.
  402. */
  403. Poll.NEVER = Infinity;
  404. })(Poll || (Poll = {}));
  405. /**
  406. * A namespace for private module data.
  407. */
  408. var Private;
  409. (function (Private) {
  410. /**
  411. * The default backoff growth rate if `backoff` is `true`.
  412. */
  413. Private.DEFAULT_BACKOFF = 3;
  414. /**
  415. * The default polling frequency.
  416. */
  417. Private.DEFAULT_FREQUENCY = {
  418. backoff: true,
  419. interval: 1000,
  420. max: 30 * 1000
  421. };
  422. /**
  423. * The default poll name.
  424. */
  425. Private.DEFAULT_NAME = 'unknown';
  426. /**
  427. * The default poll standby behavior.
  428. */
  429. Private.DEFAULT_STANDBY = 'when-hidden';
  430. /**
  431. * The first poll tick state's default values superseded in constructor.
  432. */
  433. Private.DEFAULT_STATE = {
  434. interval: Poll.NEVER,
  435. payload: null,
  436. phase: 'constructed',
  437. timestamp: new Date(0).getTime()
  438. };
  439. /**
  440. * The disposed tick state values.
  441. */
  442. Private.DISPOSED_STATE = {
  443. interval: Poll.NEVER,
  444. payload: null,
  445. phase: 'disposed',
  446. timestamp: new Date(0).getTime()
  447. };
  448. /**
  449. * Get a random integer between min and max, inclusive of both.
  450. *
  451. * #### Notes
  452. * From
  453. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random#Getting_a_random_integer_between_two_values_inclusive
  454. *
  455. * From the MDN page: It might be tempting to use Math.round() to accomplish
  456. * that, but doing so would cause your random numbers to follow a non-uniform
  457. * distribution, which may not be acceptable for your needs.
  458. */
  459. function getRandomIntInclusive(min, max) {
  460. min = Math.ceil(min);
  461. max = Math.floor(max);
  462. return Math.floor(Math.random() * (max - min + 1)) + min;
  463. }
  464. /**
  465. * Returns the number of milliseconds to sleep before the next tick.
  466. *
  467. * @param frequency - The poll's base frequency.
  468. * @param last - The poll's last tick.
  469. */
  470. function sleep(frequency, last) {
  471. var backoff = frequency.backoff, interval = frequency.interval, max = frequency.max;
  472. if (interval === Poll.NEVER) {
  473. return interval;
  474. }
  475. var growth = backoff === true ? Private.DEFAULT_BACKOFF : backoff === false ? 1 : backoff;
  476. var random = getRandomIntInclusive(interval, last.interval * growth);
  477. return Math.min(max, random);
  478. }
  479. Private.sleep = sleep;
  480. })(Private || (Private = {}));
  481. // Copyright (c) Jupyter Development Team.
  482. /**
  483. * A base class to implement rate limiters with different invocation strategies.
  484. *
  485. * @typeparam T - The resolved type of the underlying function.
  486. *
  487. * @typeparam U - The rejected type of the underlying function.
  488. */
  489. var RateLimiter = /** @class */ (function () {
  490. /**
  491. * Instantiate a rate limiter.
  492. *
  493. * @param fn - The function to rate limit.
  494. *
  495. * @param limit - The rate limit; defaults to 500ms.
  496. */
  497. function RateLimiter(fn, limit) {
  498. var _this = this;
  499. if (limit === void 0) { limit = 500; }
  500. /**
  501. * A promise that resolves on each successful invocation.
  502. */
  503. this.payload = null;
  504. this.limit = limit;
  505. this.poll = new Poll({
  506. auto: false,
  507. factory: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
  508. switch (_a.label) {
  509. case 0: return [4 /*yield*/, fn()];
  510. case 1: return [2 /*return*/, _a.sent()];
  511. }
  512. }); }); },
  513. frequency: { backoff: false, interval: Poll.NEVER, max: Poll.NEVER },
  514. standby: 'never'
  515. });
  516. this.payload = new PromiseDelegate();
  517. this.poll.ticked.connect(function (_, state) {
  518. var payload = _this.payload;
  519. if (state.phase === 'resolved') {
  520. _this.payload = new PromiseDelegate();
  521. payload.resolve(state.payload);
  522. return;
  523. }
  524. if (state.phase === 'rejected' || state.phase === 'stopped') {
  525. _this.payload = new PromiseDelegate();
  526. payload.promise.catch(function (_) { return undefined; });
  527. payload.reject(state.payload);
  528. return;
  529. }
  530. }, this);
  531. }
  532. Object.defineProperty(RateLimiter.prototype, "isDisposed", {
  533. /**
  534. * Whether the rate limiter is disposed.
  535. */
  536. get: function () {
  537. return this.payload === null;
  538. },
  539. enumerable: true,
  540. configurable: true
  541. });
  542. /**
  543. * Disposes the rate limiter.
  544. */
  545. RateLimiter.prototype.dispose = function () {
  546. if (this.isDisposed) {
  547. return;
  548. }
  549. this.payload = null;
  550. this.poll.dispose();
  551. };
  552. /**
  553. * Stop the function if it is mid-flight.
  554. */
  555. RateLimiter.prototype.stop = function () {
  556. return __awaiter(this, void 0, void 0, function () {
  557. return __generator(this, function (_a) {
  558. return [2 /*return*/, this.poll.stop()];
  559. });
  560. });
  561. };
  562. return RateLimiter;
  563. }());
  564. /**
  565. * Wraps and debounces a function that can be called multiple times and only
  566. * executes the underlying function one `interval` after the last invocation.
  567. *
  568. * @typeparam T - The resolved type of the underlying function. Defaults to any.
  569. *
  570. * @typeparam U - The rejected type of the underlying function. Defaults to any.
  571. */
  572. var Debouncer = /** @class */ (function (_super) {
  573. __extends(Debouncer, _super);
  574. function Debouncer() {
  575. return _super !== null && _super.apply(this, arguments) || this;
  576. }
  577. /**
  578. * Invokes the function and only executes after rate limit has elapsed.
  579. * Each invocation resets the timer.
  580. */
  581. Debouncer.prototype.invoke = function () {
  582. void this.poll.schedule({ interval: this.limit, phase: 'invoked' });
  583. return this.payload.promise;
  584. };
  585. return Debouncer;
  586. }(RateLimiter));
  587. /**
  588. * Wraps and throttles a function that can be called multiple times and only
  589. * executes the underlying function once per `interval`.
  590. *
  591. * @typeparam T - The resolved type of the underlying function. Defaults to any.
  592. *
  593. * @typeparam U - The rejected type of the underlying function. Defaults to any.
  594. */
  595. var Throttler = /** @class */ (function (_super) {
  596. __extends(Throttler, _super);
  597. /**
  598. * Instantiate a throttler.
  599. *
  600. * @param fn - The function being throttled.
  601. *
  602. * @param options - Throttling configuration or throttling limit in ms.
  603. *
  604. * #### Notes
  605. * The `edge` defaults to `leading`; the `limit` defaults to `500`.
  606. */
  607. function Throttler(fn, options) {
  608. var _this = _super.call(this, fn, typeof options === 'number' ? options : options && options.limit) || this;
  609. var edge = 'leading';
  610. if (typeof options !== 'number') {
  611. options = options || {};
  612. edge = 'edge' in options ? options.edge : edge;
  613. }
  614. _this._interval = edge === 'trailing' ? _this.limit : Poll.IMMEDIATE;
  615. return _this;
  616. }
  617. /**
  618. * Throttles function invocations if one is currently in flight.
  619. */
  620. Throttler.prototype.invoke = function () {
  621. if (this.poll.state.phase !== 'invoked') {
  622. void this.poll.schedule({ interval: this._interval, phase: 'invoked' });
  623. }
  624. return this.payload.promise;
  625. };
  626. return Throttler;
  627. }(RateLimiter));
  628. /**
  629. * A namespace for `Throttler` interfaces.
  630. */
  631. (function (Throttler) {
  632. })(Throttler || (Throttler = {}));
  633. export { Debouncer, Poll, RateLimiter, Throttler };
  634. //# sourceMappingURL=index.es6.js.map