@difizen/libro-common 0.0.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/es/array.d.ts +368 -0
- package/es/array.d.ts.map +1 -0
- package/es/array.js +577 -0
- package/es/display-wrapper.d.ts +6 -0
- package/es/display-wrapper.d.ts.map +1 -0
- package/es/display-wrapper.js +12 -0
- package/es/index.d.ts +11 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +10 -0
- package/es/iter.d.ts +147 -0
- package/es/iter.d.ts.map +1 -0
- package/es/iter.js +162 -0
- package/es/json.d.ts +126 -0
- package/es/json.d.ts.map +1 -0
- package/es/json.js +274 -0
- package/es/path.d.ts +97 -0
- package/es/path.d.ts.map +1 -0
- package/es/path.js +60 -0
- package/es/polling/index.d.ts +3 -0
- package/es/polling/index.d.ts.map +1 -0
- package/es/polling/index.js +2 -0
- package/es/polling/poll.d.ts +193 -0
- package/es/polling/poll.d.ts.map +1 -0
- package/es/polling/poll.js +501 -0
- package/es/polling/protocol.d.ts +120 -0
- package/es/polling/protocol.d.ts.map +1 -0
- package/es/polling/protocol.js +13 -0
- package/es/posix.d.ts +2 -0
- package/es/posix.d.ts.map +1 -0
- package/es/posix.js +71 -0
- package/es/protocol/cell-protocol.d.ts +181 -0
- package/es/protocol/cell-protocol.d.ts.map +1 -0
- package/es/protocol/cell-protocol.js +1 -0
- package/es/protocol/index.d.ts +4 -0
- package/es/protocol/index.d.ts.map +1 -0
- package/es/protocol/index.js +3 -0
- package/es/protocol/notebook-protocol.d.ts +63 -0
- package/es/protocol/notebook-protocol.d.ts.map +1 -0
- package/es/protocol/notebook-protocol.js +41 -0
- package/es/protocol/output-protocol.d.ts +125 -0
- package/es/protocol/output-protocol.d.ts.map +1 -0
- package/es/protocol/output-protocol.js +1 -0
- package/es/sanitizer.d.ts +44 -0
- package/es/sanitizer.d.ts.map +1 -0
- package/es/sanitizer.js +659 -0
- package/es/url.d.ts +98 -0
- package/es/url.d.ts.map +1 -0
- package/es/url.js +134 -0
- package/es/utils.d.ts +57 -0
- package/es/utils.d.ts.map +1 -0
- package/es/utils.js +124 -0
- package/package.json +62 -0
- package/src/array.ts +608 -0
- package/src/display-wrapper.tsx +11 -0
- package/src/index.ts +10 -0
- package/src/iter.ts +199 -0
- package/src/json.ts +321 -0
- package/src/path.ts +138 -0
- package/src/polling/index.ts +2 -0
- package/src/polling/poll.ts +508 -0
- package/src/polling/protocol.ts +145 -0
- package/src/posix.ts +75 -0
- package/src/protocol/cell-protocol.ts +215 -0
- package/src/protocol/index.ts +3 -0
- package/src/protocol/notebook-protocol.ts +73 -0
- package/src/protocol/output-protocol.ts +162 -0
- package/src/sanitizer.ts +944 -0
- package/src/url.ts +157 -0
- package/src/utils.ts +145 -0
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
var _Symbol$asyncIterator;
|
|
3
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
6
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
7
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
8
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
11
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
13
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
14
|
+
function _awaitAsyncGenerator(value) { return new _OverloadYield(value, 0); }
|
|
15
|
+
function _wrapAsyncGenerator(fn) { return function () { return new _AsyncGenerator(fn.apply(this, arguments)); }; }
|
|
16
|
+
function _AsyncGenerator(gen) { var front, back; function resume(key, arg) { try { var result = gen[key](arg), value = result.value, overloaded = value instanceof _OverloadYield; Promise.resolve(overloaded ? value.v : value).then(function (arg) { if (overloaded) { var nextKey = "return" === key ? "return" : "next"; if (!value.k || arg.done) return resume(nextKey, arg); arg = gen[nextKey](arg).value; } settle(result.done ? "return" : "normal", arg); }, function (err) { resume("throw", err); }); } catch (err) { settle("throw", err); } } function settle(type, value) { switch (type) { case "return": front.resolve({ value: value, done: !0 }); break; case "throw": front.reject(value); break; default: front.resolve({ value: value, done: !1 }); } (front = front.next) ? resume(front.key, front.arg) : back = null; } this._invoke = function (key, arg) { return new Promise(function (resolve, reject) { var request = { key: key, arg: arg, resolve: resolve, reject: reject, next: null }; back ? back = back.next = request : (front = back = request, resume(key, arg)); }); }, "function" != typeof gen.return && (this.return = void 0); }
|
|
17
|
+
_AsyncGenerator.prototype["function" == typeof Symbol && Symbol.asyncIterator || "@@asyncIterator"] = function () { return this; }, _AsyncGenerator.prototype.next = function (arg) { return this._invoke("next", arg); }, _AsyncGenerator.prototype.throw = function (arg) { return this._invoke("throw", arg); }, _AsyncGenerator.prototype.return = function (arg) { return this._invoke("return", arg); };
|
|
18
|
+
function _OverloadYield(value, kind) { this.v = value, this.k = kind; }
|
|
19
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
20
|
+
/* eslint-disable no-param-reassign */
|
|
21
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
22
|
+
|
|
23
|
+
import { Emitter, Deferred } from '@difizen/mana-common';
|
|
24
|
+
import { deepEqual } from "../json.js";
|
|
25
|
+
_Symbol$asyncIterator = Symbol.asyncIterator;
|
|
26
|
+
/**
|
|
27
|
+
* A class that wraps an asynchronous function to poll at a regular interval
|
|
28
|
+
* with exponential increases to the interval length if the poll fails.
|
|
29
|
+
*
|
|
30
|
+
* @typeparam T - The resolved type of the factory's promises.
|
|
31
|
+
* Defaults to `any`.
|
|
32
|
+
*
|
|
33
|
+
* @typeparam U - The rejected type of the factory's promises.
|
|
34
|
+
* Defaults to `any`.
|
|
35
|
+
*
|
|
36
|
+
* @typeparam V - An optional type to extend the phases supported by a poll.
|
|
37
|
+
* Defaults to `standby`, which already exists in the `Phase` type.
|
|
38
|
+
*/
|
|
39
|
+
export var Poll = /*#__PURE__*/function () {
|
|
40
|
+
/**
|
|
41
|
+
* Instantiate a new poll with exponential backoff in case of failure.
|
|
42
|
+
*
|
|
43
|
+
* @param options - The poll instantiation options.
|
|
44
|
+
*/
|
|
45
|
+
function Poll(options) {
|
|
46
|
+
var _this2 = this;
|
|
47
|
+
_classCallCheck(this, Poll);
|
|
48
|
+
this.disposeEmitter = new Emitter();
|
|
49
|
+
this._tick = new Deferred();
|
|
50
|
+
this.tickedEmitter = new Emitter();
|
|
51
|
+
// Support node and browser.
|
|
52
|
+
this.disposed = false;
|
|
53
|
+
var frequency = options.frequency || {};
|
|
54
|
+
var max = Math.max(frequency.interval || 0, frequency.max || 0, Private.DEFAULT_FREQUENCY.max);
|
|
55
|
+
this._frequency = _objectSpread(_objectSpread(_objectSpread({}, Private.DEFAULT_FREQUENCY), frequency), {
|
|
56
|
+
max: max
|
|
57
|
+
});
|
|
58
|
+
this._factory = options.factory;
|
|
59
|
+
this._standby = options.standby || Private.DEFAULT_STANDBY;
|
|
60
|
+
this._state = _objectSpread(_objectSpread({}, Private.DEFAULT_STATE), {}, {
|
|
61
|
+
timestamp: new Date().getTime()
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Normalize poll frequency `max` to be the greater of
|
|
65
|
+
// default `max`, `options.frequency.max`, or `options.frequency.interval`.
|
|
66
|
+
|
|
67
|
+
this.name = options.name || Private.DEFAULT_NAME;
|
|
68
|
+
if ('auto' in options ? options.auto : true) {
|
|
69
|
+
setTimeout(function () {
|
|
70
|
+
return _this2.start();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The name of the poll.
|
|
77
|
+
*/
|
|
78
|
+
_createClass(Poll, [{
|
|
79
|
+
key: "onDispose",
|
|
80
|
+
get:
|
|
81
|
+
/**
|
|
82
|
+
* A signal emitted when the poll is disposed.
|
|
83
|
+
*/
|
|
84
|
+
function get() {
|
|
85
|
+
return this.disposeEmitter.event;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The polling frequency parameters.
|
|
90
|
+
*/
|
|
91
|
+
}, {
|
|
92
|
+
key: "frequency",
|
|
93
|
+
get: function get() {
|
|
94
|
+
return this._frequency;
|
|
95
|
+
},
|
|
96
|
+
set: function set(frequency) {
|
|
97
|
+
if (this.isDisposed || deepEqual(frequency, this.frequency || {})) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
var interval = frequency.interval,
|
|
101
|
+
max = frequency.max;
|
|
102
|
+
var backoff = frequency.backoff;
|
|
103
|
+
interval = Math.round(interval);
|
|
104
|
+
max = Math.round(max);
|
|
105
|
+
if (typeof backoff === 'number' && backoff < 1) {
|
|
106
|
+
throw new Error('Poll backoff growth factor must be at least 1');
|
|
107
|
+
}
|
|
108
|
+
if ((interval < 0 || interval > max) && interval !== Poll.NEVER) {
|
|
109
|
+
throw new Error('Poll interval must be between 0 and max');
|
|
110
|
+
}
|
|
111
|
+
if (max > Poll.MAX_INTERVAL && max !== Poll.NEVER) {
|
|
112
|
+
throw new Error("Max interval must be less than ".concat(Poll.MAX_INTERVAL));
|
|
113
|
+
}
|
|
114
|
+
this._frequency = {
|
|
115
|
+
backoff: backoff,
|
|
116
|
+
interval: interval,
|
|
117
|
+
max: max
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Whether the poll is disposed.
|
|
123
|
+
*/
|
|
124
|
+
}, {
|
|
125
|
+
key: "isDisposed",
|
|
126
|
+
get: function get() {
|
|
127
|
+
return this.state.phase === 'disposed';
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Indicates when the poll switches to standby.
|
|
132
|
+
*/
|
|
133
|
+
}, {
|
|
134
|
+
key: "standby",
|
|
135
|
+
get: function get() {
|
|
136
|
+
return this._standby;
|
|
137
|
+
},
|
|
138
|
+
set: function set(standby) {
|
|
139
|
+
if (this.isDisposed || this.standby === standby) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
this._standby = standby;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The poll state, which is the content of the current poll tick.
|
|
147
|
+
*/
|
|
148
|
+
}, {
|
|
149
|
+
key: "state",
|
|
150
|
+
get: function get() {
|
|
151
|
+
return this._state;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* A promise that resolves when the poll next ticks.
|
|
156
|
+
*/
|
|
157
|
+
}, {
|
|
158
|
+
key: "tick",
|
|
159
|
+
get: function get() {
|
|
160
|
+
return this._tick.promise;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* A signal emitted when the poll ticks and fires off a new request.
|
|
165
|
+
*/
|
|
166
|
+
}, {
|
|
167
|
+
key: "ticked",
|
|
168
|
+
get: function get() {
|
|
169
|
+
return this.tickedEmitter.event;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Return an async iterator that yields every tick.
|
|
174
|
+
*/
|
|
175
|
+
}, {
|
|
176
|
+
key: _Symbol$asyncIterator,
|
|
177
|
+
value: function value() {
|
|
178
|
+
var _this = this;
|
|
179
|
+
return _wrapAsyncGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
180
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
181
|
+
while (1) switch (_context.prev = _context.next) {
|
|
182
|
+
case 0:
|
|
183
|
+
if (_this.isDisposed) {
|
|
184
|
+
_context.next = 7;
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
_context.next = 3;
|
|
188
|
+
return _this.state;
|
|
189
|
+
case 3:
|
|
190
|
+
_context.next = 5;
|
|
191
|
+
return _awaitAsyncGenerator(_this.tick.catch(function () {
|
|
192
|
+
return undefined;
|
|
193
|
+
}));
|
|
194
|
+
case 5:
|
|
195
|
+
_context.next = 0;
|
|
196
|
+
break;
|
|
197
|
+
case 7:
|
|
198
|
+
case "end":
|
|
199
|
+
return _context.stop();
|
|
200
|
+
}
|
|
201
|
+
}, _callee);
|
|
202
|
+
}))();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Dispose the poll.
|
|
207
|
+
*/
|
|
208
|
+
}, {
|
|
209
|
+
key: "dispose",
|
|
210
|
+
value: function dispose() {
|
|
211
|
+
if (this.isDisposed) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
this._state = _objectSpread(_objectSpread({}, Private.DISPOSED_STATE), {}, {
|
|
215
|
+
timestamp: new Date().getTime()
|
|
216
|
+
});
|
|
217
|
+
this._tick.promise.catch(function () {
|
|
218
|
+
return undefined;
|
|
219
|
+
});
|
|
220
|
+
this._tick.reject(new Error("Poll (".concat(this.name, ") is disposed.")));
|
|
221
|
+
this.disposeEmitter.fire(undefined);
|
|
222
|
+
this.tickedEmitter.dispose();
|
|
223
|
+
this.disposed = true;
|
|
224
|
+
this.disposeEmitter.dispose();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Refreshes the poll. Schedules `refreshed` tick if necessary.
|
|
229
|
+
*
|
|
230
|
+
* @returns A promise that resolves after tick is scheduled and never rejects.
|
|
231
|
+
*
|
|
232
|
+
* #### Notes
|
|
233
|
+
* The returned promise resolves after the tick is scheduled, but before
|
|
234
|
+
* the polling action is run. To wait until after the poll action executes,
|
|
235
|
+
* await the `poll.tick` promise: `await poll.refresh(); await poll.tick;`
|
|
236
|
+
*/
|
|
237
|
+
}, {
|
|
238
|
+
key: "refresh",
|
|
239
|
+
value: function refresh() {
|
|
240
|
+
return this.schedule({
|
|
241
|
+
cancel: function cancel(_ref) {
|
|
242
|
+
var phase = _ref.phase;
|
|
243
|
+
return phase === 'refreshed';
|
|
244
|
+
},
|
|
245
|
+
interval: Poll.IMMEDIATE,
|
|
246
|
+
phase: 'refreshed'
|
|
247
|
+
});
|
|
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
|
+
}, {
|
|
264
|
+
key: "schedule",
|
|
265
|
+
value: function () {
|
|
266
|
+
var _schedule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
267
|
+
var _this3 = this;
|
|
268
|
+
var next,
|
|
269
|
+
pending,
|
|
270
|
+
scheduled,
|
|
271
|
+
state,
|
|
272
|
+
execute,
|
|
273
|
+
_args2 = arguments;
|
|
274
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
275
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
276
|
+
case 0:
|
|
277
|
+
next = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
|
|
278
|
+
if (!this.isDisposed) {
|
|
279
|
+
_context2.next = 3;
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
return _context2.abrupt("return");
|
|
283
|
+
case 3:
|
|
284
|
+
if (!(next.cancel && next.cancel(this.state))) {
|
|
285
|
+
_context2.next = 5;
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
return _context2.abrupt("return");
|
|
289
|
+
case 5:
|
|
290
|
+
// Update poll state.
|
|
291
|
+
pending = this._tick;
|
|
292
|
+
scheduled = new Deferred();
|
|
293
|
+
state = _objectSpread({
|
|
294
|
+
interval: this.frequency.interval,
|
|
295
|
+
payload: null,
|
|
296
|
+
phase: 'standby',
|
|
297
|
+
timestamp: new Date().getTime()
|
|
298
|
+
}, next);
|
|
299
|
+
this._state = state;
|
|
300
|
+
this._tick = scheduled;
|
|
301
|
+
|
|
302
|
+
// Clear the schedule if possible.
|
|
303
|
+
clearTimeout(this._timeout);
|
|
304
|
+
|
|
305
|
+
// Emit ticked signal, resolve pending promise, and await its settlement.
|
|
306
|
+
this.tickedEmitter.fire(this.state);
|
|
307
|
+
pending.resolve(this);
|
|
308
|
+
_context2.next = 15;
|
|
309
|
+
return pending.promise;
|
|
310
|
+
case 15:
|
|
311
|
+
if (!(state.interval === Poll.NEVER)) {
|
|
312
|
+
_context2.next = 18;
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
this._timeout = undefined;
|
|
316
|
+
return _context2.abrupt("return");
|
|
317
|
+
case 18:
|
|
318
|
+
// Schedule next execution and cache its timeout handle.
|
|
319
|
+
execute = function execute() {
|
|
320
|
+
if (_this3.isDisposed || _this3.tick !== scheduled.promise) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
_this3._execute();
|
|
324
|
+
};
|
|
325
|
+
this._timeout = setTimeout(execute, state.interval);
|
|
326
|
+
case 20:
|
|
327
|
+
case "end":
|
|
328
|
+
return _context2.stop();
|
|
329
|
+
}
|
|
330
|
+
}, _callee2, this);
|
|
331
|
+
}));
|
|
332
|
+
function schedule() {
|
|
333
|
+
return _schedule.apply(this, arguments);
|
|
334
|
+
}
|
|
335
|
+
return schedule;
|
|
336
|
+
}()
|
|
337
|
+
/**
|
|
338
|
+
* Starts the poll. Schedules `started` tick if necessary.
|
|
339
|
+
*
|
|
340
|
+
* @returns A promise that resolves after tick is scheduled and never rejects.
|
|
341
|
+
*/
|
|
342
|
+
}, {
|
|
343
|
+
key: "start",
|
|
344
|
+
value: function start() {
|
|
345
|
+
return this.schedule({
|
|
346
|
+
cancel: function cancel(_ref2) {
|
|
347
|
+
var phase = _ref2.phase;
|
|
348
|
+
return phase !== 'constructed' && phase !== 'standby' && phase !== 'stopped';
|
|
349
|
+
},
|
|
350
|
+
interval: Poll.IMMEDIATE,
|
|
351
|
+
phase: 'started'
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Stops the poll. Schedules `stopped` tick if necessary.
|
|
357
|
+
*
|
|
358
|
+
* @returns A promise that resolves after tick is scheduled and never rejects.
|
|
359
|
+
*/
|
|
360
|
+
}, {
|
|
361
|
+
key: "stop",
|
|
362
|
+
value: function stop() {
|
|
363
|
+
return this.schedule({
|
|
364
|
+
cancel: function cancel(_ref3) {
|
|
365
|
+
var phase = _ref3.phase;
|
|
366
|
+
return phase === 'stopped';
|
|
367
|
+
},
|
|
368
|
+
interval: Poll.NEVER,
|
|
369
|
+
phase: 'stopped'
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Execute a new poll factory promise or stand by if necessary.
|
|
375
|
+
*/
|
|
376
|
+
}, {
|
|
377
|
+
key: "_execute",
|
|
378
|
+
value: function _execute() {
|
|
379
|
+
var _this4 = this;
|
|
380
|
+
var standby = typeof this.standby === 'function' ? this.standby() : this.standby;
|
|
381
|
+
standby = standby === 'never' ? false : standby === 'when-hidden' ? !!(typeof document !== 'undefined' && document && document.hidden) : standby;
|
|
382
|
+
|
|
383
|
+
// If in standby mode schedule next tick without calling the factory.
|
|
384
|
+
if (standby) {
|
|
385
|
+
void this.schedule();
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
var pending = this.tick;
|
|
389
|
+
this._factory(this.state).then(function (resolved) {
|
|
390
|
+
if (_this4.isDisposed || _this4.tick !== pending) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
void _this4.schedule({
|
|
394
|
+
payload: resolved,
|
|
395
|
+
phase: _this4.state.phase === 'rejected' ? 'reconnected' : 'resolved'
|
|
396
|
+
});
|
|
397
|
+
return;
|
|
398
|
+
}).catch(function (rejected) {
|
|
399
|
+
if (_this4.isDisposed || _this4.tick !== pending) {
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
void _this4.schedule({
|
|
403
|
+
interval: Private.sleep(_this4.frequency, _this4.state),
|
|
404
|
+
payload: rejected,
|
|
405
|
+
phase: 'rejected'
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
}]);
|
|
410
|
+
return Poll;
|
|
411
|
+
}();
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* A namespace for `Poll` types, interfaces, and statics.
|
|
415
|
+
*/
|
|
416
|
+
(function (_Poll) {
|
|
417
|
+
/**
|
|
418
|
+
* A promise factory that returns an individual poll request.
|
|
419
|
+
*
|
|
420
|
+
* @typeparam T - The resolved type of the factory's promises.
|
|
421
|
+
*
|
|
422
|
+
* @typeparam U - The rejected type of the factory's promises.
|
|
423
|
+
*
|
|
424
|
+
* @typeparam V - The type to extend the phases supported by a poll.
|
|
425
|
+
*/
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Indicates when the poll switches to standby.
|
|
429
|
+
*/
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Instantiation options for polls.
|
|
433
|
+
*
|
|
434
|
+
* @typeparam T - The resolved type of the factory's promises.
|
|
435
|
+
*
|
|
436
|
+
* @typeparam U - The rejected type of the factory's promises.
|
|
437
|
+
*
|
|
438
|
+
* @typeparam V - The type to extend the phases supported by a poll.
|
|
439
|
+
*/
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* An interval value (0ms) that indicates the poll should tick immediately.
|
|
443
|
+
*/
|
|
444
|
+
var IMMEDIATE = _Poll.IMMEDIATE = 0;
|
|
445
|
+
var MAX_INTERVAL = _Poll.MAX_INTERVAL = 2147483647;
|
|
446
|
+
var NEVER = _Poll.NEVER = Infinity;
|
|
447
|
+
})(Poll || (Poll = {}));
|
|
448
|
+
/**
|
|
449
|
+
* A namespace for protected module data.
|
|
450
|
+
*/
|
|
451
|
+
var Private;
|
|
452
|
+
(function (_Private) {
|
|
453
|
+
var DEFAULT_BACKOFF = _Private.DEFAULT_BACKOFF = 3;
|
|
454
|
+
var DEFAULT_FREQUENCY = _Private.DEFAULT_FREQUENCY = {
|
|
455
|
+
backoff: true,
|
|
456
|
+
interval: 1000,
|
|
457
|
+
max: 30 * 1000
|
|
458
|
+
};
|
|
459
|
+
var DEFAULT_NAME = _Private.DEFAULT_NAME = 'unknown';
|
|
460
|
+
var DEFAULT_STANDBY = _Private.DEFAULT_STANDBY = 'when-hidden';
|
|
461
|
+
var DEFAULT_STATE = _Private.DEFAULT_STATE = {
|
|
462
|
+
interval: Poll.NEVER,
|
|
463
|
+
payload: null,
|
|
464
|
+
phase: 'constructed',
|
|
465
|
+
timestamp: new Date(0).getTime()
|
|
466
|
+
};
|
|
467
|
+
var DISPOSED_STATE = _Private.DISPOSED_STATE = {
|
|
468
|
+
interval: Poll.NEVER,
|
|
469
|
+
payload: null,
|
|
470
|
+
phase: 'disposed',
|
|
471
|
+
timestamp: new Date(0).getTime()
|
|
472
|
+
};
|
|
473
|
+
function sleep(frequency, last) {
|
|
474
|
+
var backoff = frequency.backoff,
|
|
475
|
+
interval = frequency.interval,
|
|
476
|
+
max = frequency.max;
|
|
477
|
+
if (interval === Poll.NEVER) {
|
|
478
|
+
return interval;
|
|
479
|
+
}
|
|
480
|
+
var growth = backoff === true ? DEFAULT_BACKOFF : backoff === false ? 1 : backoff;
|
|
481
|
+
var random = getRandomIntInclusive(interval, last.interval * growth);
|
|
482
|
+
return Math.min(max, random);
|
|
483
|
+
}
|
|
484
|
+
_Private.sleep = sleep;
|
|
485
|
+
})(Private || (Private = {}));
|
|
486
|
+
/**
|
|
487
|
+
* Get a random integer between min and max, inclusive of both.
|
|
488
|
+
*
|
|
489
|
+
* #### Notes
|
|
490
|
+
* From
|
|
491
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random#Getting_a_random_integer_between_two_values_inclusive
|
|
492
|
+
*
|
|
493
|
+
* From the MDN page: It might be tempting to use Math.round() to accomplish
|
|
494
|
+
* that, but doing so would cause your random numbers to follow a non-uniform
|
|
495
|
+
* distribution, which may not be acceptable for your needs.
|
|
496
|
+
*/
|
|
497
|
+
function getRandomIntInclusive(min, max) {
|
|
498
|
+
min = Math.ceil(min);
|
|
499
|
+
max = Math.floor(max);
|
|
500
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
501
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { Event } from '@difizen/mana-common';
|
|
2
|
+
/**
|
|
3
|
+
* A readonly poll that calls an asynchronous function with each tick.
|
|
4
|
+
*
|
|
5
|
+
* @typeparam T - The resolved type of the factory's promises.
|
|
6
|
+
*
|
|
7
|
+
* @typeparam U - The rejected type of the factory's promises.
|
|
8
|
+
*
|
|
9
|
+
* @typeparam V - The type to extend the phases supported by a poll.
|
|
10
|
+
*/
|
|
11
|
+
export interface IPoll<T, U, V extends string> extends AsyncIterable<IPoll.State<T, U, V>> {
|
|
12
|
+
/**
|
|
13
|
+
* A signal emitted when the poll is disposed.
|
|
14
|
+
*/
|
|
15
|
+
readonly onDispose: Event<void>;
|
|
16
|
+
/**
|
|
17
|
+
* The polling frequency data.
|
|
18
|
+
*/
|
|
19
|
+
readonly frequency: IPoll.Frequency;
|
|
20
|
+
/**
|
|
21
|
+
* Whether the poll is disposed.
|
|
22
|
+
*/
|
|
23
|
+
readonly disposed: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The name of the poll.
|
|
26
|
+
*/
|
|
27
|
+
readonly name: string;
|
|
28
|
+
/**
|
|
29
|
+
* The poll state, which is the content of the currently-scheduled poll tick.
|
|
30
|
+
*/
|
|
31
|
+
readonly state: IPoll.State<T, U, V>;
|
|
32
|
+
/**
|
|
33
|
+
* A promise that resolves when the currently-scheduled tick completes.
|
|
34
|
+
*
|
|
35
|
+
* #### Notes
|
|
36
|
+
* Usually this will resolve after `state.interval` milliseconds from
|
|
37
|
+
* `state.timestamp`. It can resolve earlier if the user starts or refreshes
|
|
38
|
+
* the poll, etc.
|
|
39
|
+
*/
|
|
40
|
+
readonly tick: Promise<IPoll<T, U, V>>;
|
|
41
|
+
/**
|
|
42
|
+
* A signal emitted when the poll state changes, i.e., a new tick is scheduled.
|
|
43
|
+
*/
|
|
44
|
+
readonly ticked: Event<IPoll.State<T, U, V>>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A namespace for `IPoll` types.
|
|
48
|
+
*/
|
|
49
|
+
export declare namespace IPoll {
|
|
50
|
+
/**
|
|
51
|
+
* The polling frequency parameters.
|
|
52
|
+
*
|
|
53
|
+
* #### Notes
|
|
54
|
+
* We implement the "decorrelated jitter" strategy from
|
|
55
|
+
* https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/.
|
|
56
|
+
* Essentially, if consecutive retries are needed, we choose an integer:
|
|
57
|
+
* `sleep = min(max, rand(interval, backoff * sleep))`
|
|
58
|
+
* This ensures that the poll is never less than `interval`, and nicely
|
|
59
|
+
* spreads out retries for consecutive tries. Over time, if (interval < max),
|
|
60
|
+
* the random number will be above `max` about (1 - 1/backoff) of the time
|
|
61
|
+
* (sleeping the `max`), and the rest of the time the sleep will be a random
|
|
62
|
+
* number below `max`, decorrelating our trigger time from other pollers.
|
|
63
|
+
*/
|
|
64
|
+
type Frequency = {
|
|
65
|
+
/**
|
|
66
|
+
* Whether poll frequency backs off (boolean) or the backoff growth rate
|
|
67
|
+
* (float > 1).
|
|
68
|
+
*
|
|
69
|
+
* #### Notes
|
|
70
|
+
* If `true`, the default backoff growth rate is `3`.
|
|
71
|
+
*/
|
|
72
|
+
readonly backoff: boolean | number;
|
|
73
|
+
/**
|
|
74
|
+
* The basic polling interval in milliseconds (integer).
|
|
75
|
+
*/
|
|
76
|
+
readonly interval: number;
|
|
77
|
+
/**
|
|
78
|
+
* The maximum milliseconds (integer) between poll requests.
|
|
79
|
+
*/
|
|
80
|
+
readonly max: number;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* The phase of the poll when the current tick was scheduled.
|
|
84
|
+
*
|
|
85
|
+
* @typeparam T - A type for any additional tick phases a poll supports.
|
|
86
|
+
*/
|
|
87
|
+
type Phase<T extends string> = T | 'constructed' | 'disposed' | 'reconnected' | 'refreshed' | 'rejected' | 'resolved' | 'standby' | 'started' | 'stopped';
|
|
88
|
+
/**
|
|
89
|
+
* Definition of poll state at any given time.
|
|
90
|
+
*
|
|
91
|
+
* @typeparam T - The resolved type of the factory's promises.
|
|
92
|
+
*
|
|
93
|
+
* @typeparam U - The rejected type of the factory's promises.
|
|
94
|
+
*
|
|
95
|
+
* @typeparam V - The type to extend the phases supported by a poll.
|
|
96
|
+
*/
|
|
97
|
+
type State<T, U, V extends string> = {
|
|
98
|
+
/**
|
|
99
|
+
* The number of milliseconds until the current tick resolves.
|
|
100
|
+
*/
|
|
101
|
+
readonly interval: number;
|
|
102
|
+
/**
|
|
103
|
+
* The payload of the last poll resolution or rejection.
|
|
104
|
+
*
|
|
105
|
+
* #### Notes
|
|
106
|
+
* The payload is `null` unless the `phase` is `'reconnected`, `'resolved'`,
|
|
107
|
+
* or `'rejected'`. Its type is `T` for resolutions and `U` for rejections.
|
|
108
|
+
*/
|
|
109
|
+
readonly payload: T | U | null;
|
|
110
|
+
/**
|
|
111
|
+
* The current poll phase.
|
|
112
|
+
*/
|
|
113
|
+
readonly phase: Phase<V>;
|
|
114
|
+
/**
|
|
115
|
+
* The timestamp for when this tick was scheduled.
|
|
116
|
+
*/
|
|
117
|
+
readonly timestamp: number;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/polling/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAElD;;;;;;;;GAQG;AACH,MAAM,WAAW,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,MAAM,CAC3C,SAAQ,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC3C;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IAEhC;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC;IAEpC;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAErC;;;;;;;OAOG;IACH,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEvC;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;CAC9C;AAED;;GAEG;AACH,yBAAiB,KAAK,CAAC;IACrB;;;;;;;;;;;;;OAaG;IACH,KAAY,SAAS,GAAG;QACtB;;;;;;WAMG;QACH,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC;QAEnC;;WAEG;QACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAE1B;;WAEG;QACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;KACtB,CAAC;IAEF;;;;OAIG;IACH,KAAY,KAAK,CAAC,CAAC,SAAS,MAAM,IAC9B,CAAC,GACD,aAAa,GACb,UAAU,GACV,aAAa,GACb,WAAW,GACX,UAAU,GACV,UAAU,GACV,SAAS,GACT,SAAS,GACT,SAAS,CAAC;IAEd;;;;;;;;OAQG;IACH,KAAY,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,MAAM,IAAI;QAC1C;;WAEG;QACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAE1B;;;;;;WAMG;QACH,QAAQ,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;QAE/B;;WAEG;QACH,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;QAEzB;;WAEG;QACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;KAC5B,CAAC;CACH"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A readonly poll that calls an asynchronous function with each tick.
|
|
3
|
+
*
|
|
4
|
+
* @typeparam T - The resolved type of the factory's promises.
|
|
5
|
+
*
|
|
6
|
+
* @typeparam U - The rejected type of the factory's promises.
|
|
7
|
+
*
|
|
8
|
+
* @typeparam V - The type to extend the phases supported by a poll.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* A namespace for `IPoll` types.
|
|
12
|
+
*/
|
|
13
|
+
export var IPoll;
|
package/es/posix.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"posix.d.ts","sourceRoot":"","sources":["../src/posix.ts"],"names":[],"mappings":"AA0DA,eAAO,MAAM,IAAI,YAAsB,MAAM,EAAE,WAgB9C,CAAC"}
|