uneventful 0.0.9 → 0.0.11
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/README.md +2 -2
- package/dist/call-or-wait-EzXJX5Dq.mjs +111 -0
- package/dist/ext.d.ts +260 -0
- package/dist/ext.mjs +112 -0
- package/dist/{call-or-wait-DpJBh_pS.mjs → jobutils-Dvu-e99o.mjs} +64 -167
- package/dist/mod.d.ts +65 -5
- package/dist/mod.mjs +11 -9
- package/dist/shared.d.ts +109 -0
- package/dist/shared.mjs +52 -0
- package/dist/signals.d.ts +26 -4
- package/dist/signals.mjs +70 -47
- package/dist/{utils-P0JEpWXG.mjs → utils-cyEhnyp7.mjs} +16 -7
- package/dist/utils.d.ts +77 -26
- package/dist/utils.mjs +1 -2
- package/package.json +27 -11
- package/dist/call-or-wait-DpJBh_pS.mjs.map +0 -1
- package/dist/mod.mjs.map +0 -1
- package/dist/signals.mjs.map +0 -1
- package/dist/utils-P0JEpWXG.mjs.map +0 -1
- package/dist/utils.mjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils-P0JEpWXG.mjs","sources":["../src/defer.ts","../src/scheduling.ts","../src/utils.ts"],"sourcesContent":["/**\n * Invoke a no-argument function as a microtask, using queueMicrotask or Promise.resolve().then()\n *\n * @category Scheduling\n */\nexport let defer: (cb: () => any) => void =\n typeof queueMicrotask === \"function\" ?\n queueMicrotask :\n (p => (cb: () => any) => p.then(cb))(Promise.resolve());\n\n/**\n * @internal For testing use only!\n *\n */\nexport function setDefer(fn: typeof defer) {\n defer = fn;\n}","import { defer } from \"./defer.ts\";\n\n/** Scheduler state flags */\nconst enum Is {\n Unset = 0,\n _ = 1,\n Running = _ << 0,\n Scheduled = _ << 1,\n}\n\n/**\n * A generic batch processing queue, implemented as a set. (So items are\n * processed at most once per batch run.)\n *\n * @template T The type of items that will be in the batch\n *\n * @category Scheduling\n */\nexport interface Batch<T> {\n /** Is the batch processing function currently running? */\n isRunning(): boolean;\n\n /** Is the batch currently empty? */\n isEmpty(): boolean;\n\n /**\n * Add an item to the batch. Schedules the batch for processing if the\n * batch was empty and is not already scheduled. (Does nothing if the\n * item is already in the batch.)\n */\n add(item: T): void;\n\n /** Remove an item from the batch. (Does not affect the schedule.) */\n delete(item: T): void;\n\n /** Is the item in the batch? */\n has(item: any): boolean;\n\n /**\n * Process the batch now by calling the processing function, unless the\n * batch is empty or already running. If the processing function exits\n * without fully emptying the batch (due to errors, time limits, etc.),\n * another flush will be scheduled via the batch's scheduler (unless one is\n * already scheduled).\n */\n readonly flush: () => void;\n}\n\n\n/**\n * Create a batch processing queue from the given processing loop and scheduling\n * function.\n *\n * @template T The type of items that will be in the batch\n *\n * @param process A function taking a set of items. It should remove items from\n * the set, usually *before* processing them. (So that the batch won't\n * perpetually block on that item in case of a persistent error.) If the\n * processing function doesn't remove all items from the set, another processing\n * pass will be done later. (This allows you to rate-limit processing, so as\n * not to hog the current thread.)\n *\n * @param sched A single-argument scheduling function (like\n * requestAnimationFrame, setImmediate, or queueMicrotask). The batch will call\n * it from time to time with a single callback. The scheduling function should\n * then arrange for that callback to be invoked *once* at some future point,\n * when it is the desired time for pending items to be processed. If no\n * function is given (or it's undefined/null), {@link defer} is used.\n *\n * @returns a {@link Batch} that items can be added to for later processing.\n *\n * @category Scheduling\n */\nexport function batch<T>(process: (items: Set<T>) => void, sched?: (cb: () => unknown) => unknown): Batch<T> {\n return new _Batch(process, sched);\n}\n\n/**\n * A generic queue for things that need to be run at-most-once per item\n * per timeframe.\n *\n * @category Scheduling\n */\nclass _Batch<T> implements Batch<T> {\n protected _flags: Is = Is.Unset;\n protected readonly q = new Set<T>();\n\n constructor(\n protected readonly reap: (queue: Set<T>) => void,\n protected readonly sched: ((cb: () => unknown) => unknown) | undefined | null,\n ) {}\n\n /** Is this queue currently running? */\n isRunning() { return !!(this._flags & Is.Running); }\n\n /** Is this queue currently empty? */\n isEmpty() { return !this.q.size; }\n\n add(subject: T) {\n this.q.size || this._flags & (Is.Running|Is.Scheduled) || this._sched();\n this.q.add(subject);\n }\n\n delete(subject: any) {\n this.q.delete(subject);\n }\n\n has(subject: any) {\n return this.q.has(subject);\n }\n\n protected _sched() {\n this._flags |= Is.Scheduled;\n (this.sched || defer)(this._run);\n }\n\n protected _run = () => {\n this._flags &= ~Is.Scheduled;\n this.flush();\n }\n\n /** Run all pending items */\n flush = () => {\n // already running? skip it\n if (this._flags & Is.Running) return;\n const {q: queue} = this;\n // nothing to do? skip it\n if (!queue.size) return;\n this._flags |= Is.Running;\n try {\n this.reap(queue);\n } finally {\n this._flags &= ~Is.Running;\n // schedule again if we're stopping early due to error\n !queue.size || (this._flags & Is.Scheduled) || this._sched();\n }\n }\n}\n","/**\n * Utilities that aren't part of Uneventful's core feature set, but are exposed\n * anyway, because they're boilerplate that can save duplication elsewhere if\n * you happen to need them.\n *\n * @module uneventful/utils\n */\nimport { AnyFunction } from \"./types.ts\";\n\n/**\n * Shorthand for Array.isArray()\n *\n * @category Data Structures\n */\nexport const isArray = Array.isArray;\n\n/**\n * Return true if the supplied parameters are the same object/vaue, or are\n * arrays with identical contents.\n *\n * @category Data Structures\n */\nexport function arrayEq<T>(a: readonly T[] | null | undefined, b: readonly T[] | null | undefined): boolean;\nexport function arrayEq<T>(a: any, b: any): boolean;\nexport function arrayEq<T>(a: readonly T[] | null | undefined, b: readonly T[] | null | undefined) {\n return (a===b) || (isArray(a) && isArray(b) && a.length === b.length && a.every(same, b))\n}\n\nfunction same(this: any[], item: any, idx: number) { return item === this[idx]; }\n\n/**\n * Set a value in a Map or WeakMap, and return the value.\n *\n * Commonly used with constructions like `return map.get(key) ?? setMap(map,\n * key, calculateDefault())`.\n *\n * @template K The type of key accepted by the map\n * @template V The type of value accepted by the map\n *\n * @category Data Structures\n */\nexport function setMap<K, V>(map: { set(key: K, val: V): void; }, key: K, val: V) {\n map.set(key, val);\n return val;\n}\n\n/**\n * Is the given value a function? (Shorthand for `typeof f === \"function\"`)\n *\n * @category Functional Programming\n */\nexport function isFunction(f: any): f is Function {\n return typeof f === \"function\";\n}\n\n/**\n * This class hides the implementation details of inheriting from Function in\n * the documentation. (By default, typedoc exposes all the inherited properties\n * and members, which we don't want. By inheriting from it instead of from\n * Function, we keep the documentation free of unimportant details.)\n *\n * The way this works is that you subclass CallableObject and define a\n * constructor that calls `super(someClosure)` where `someClosure` is a unique\n * function object, which will then pick up any properties or methods defined by\n * the subclass.\n *\n * @template T The call/return signature that instances of the class will\n * implement.\n *\n * @category Functional Programming\n */\n//@ts-ignore not really a duplicate\nexport declare class CallableObject<T extends AnyFunction> extends Function {\n /**\n * @param fn A unique function or closure, to be passed to super() in a\n * subclass. The function object will gain a prototype from `new.target`,\n * thereby picking up any properties or methods defined by the class,\n * and becoming `this` for the calling constructor.\n *\n * (Note that calling the constructor by any means other than super() from\n * a constructor will result in an error or some other unhelpful result.)\n */\n constructor(fn: T);\n /** @internal */ declare length: number;\n /** @internal */ declare arguments: any;\n /** @internal */ declare caller: Function;\n /** @internal */ declare prototype: any;\n /** @internal */ declare name: string;\n}\n//@ts-ignore CallableObject<T> adheres to the constraint of T in its *implementation*\nexport interface CallableObject<T extends AnyFunction> extends T {\n /** @internal */ [Symbol.hasInstance](value: any): boolean;\n /** @internal */ apply(this: Function, thisArg: any, argArray?: any): any;\n /** @internal */ bind(this: Function, thisArg: any, ...argArray: any[]): any;\n /** @internal */ call(this: Function, thisArg: any, ...argArray: any[]): any;\n /** @internal */ toString(): string;\n}\n//@ts-ignore This is the real implementation of the above declarations\nexport const CallableObject = /* @__PURE__ */ ( () => <typeof CallableObject> Object.assign(\n function CallableObject<T>(fn: T) { return Object.setPrototypeOf(fn, new.target.prototype); },\n {prototype: Function.prototype } // No need to have extra prototypes in the chain\n))();\n\nexport { batch, type Batch } from \"./scheduling.ts\";\n\n/**\n * Calls the `target` function with the given object as the `this` value and the\n * elements of given array as the arguments.\n *\n * @category Functional Programming\n */\nexport const apply = Reflect.apply;\n\n/**\n * A pseudo-constructor for the abstract ancestor type of all generators,\n * useful for testing whether something is `instanceof Generator`.\n *\n * @category Data Structures\n */\nexport const GeneratorBase = /* @__PURE__ */ (() => {\n function G() {}; G.prototype = (function *(){}).constructor.prototype.prototype;\n return G as any as abstract new () => Generator;\n})()\n"],"names":[],"mappings":"AAAU,IAAC,KAAK,GAAG,OAAO,cAAc,KAAK,UAAU,GAAG,cAAc,mBAAmB,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,OAAO,EAAE;;ACQjI,SAAS,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE;AACtC,EAAE,OAAO,IAAI,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACpC,CAAC;AACD,MAAM,MAAM,CAAC;AACb,EAAE,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE;AAC3B,IAAI,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;AACrB,IAAI,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;AACvB,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,aAAa;AAChC,IAAI,IAAI,CAAC,CAAC,mBAAmB,IAAI,GAAG,EAAE,CAAC;AACvC,IAAI,IAAI,CAAC,IAAI,GAAG,MAAM;AACtB,MAAM,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,iBAAiB;AACxC,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;AACnB,KAAK,CAAC;AACN;AACA,IAAI,IAAI,CAAC,KAAK,GAAG,MAAM;AACvB,MAAM,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;AACzB,QAAQ,OAAO;AACf,MAAM,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;AAChC,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI;AACrB,QAAQ,OAAO;AACf,MAAM,IAAI,CAAC,MAAM,IAAI,CAAC,eAAe;AACrC,MA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