uneventful 0.0.8 → 0.0.9

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.
@@ -679,7 +679,7 @@ function task(fn, _ctx, desc) {
679
679
  if (desc)
680
680
  return { ...desc, value: task(desc.value) };
681
681
  return function(...args) {
682
- return start(fn.bind(this, ...args));
682
+ return start(() => apply(fn, this, args));
683
683
  };
684
684
  }
685
685
 
@@ -702,4 +702,4 @@ function mustBeSourceOrSignal() {
702
702
  }
703
703
 
704
704
  export { nativePromise as A, makeJob as B, CancelResult as C, pipe as D, ErrorResult as E, compose as F, into as G, isJobActive as H, IsStream as I, timeout as J, abortSignal as K, task as L, swapCtx as M, nullCtx as N, makeCtx as O, freeCtx as P, ValueResult as V, rejecter as a, resolve as b, backpressure as c, detached as d, isUnhandled as e, markHandled as f, getJob as g, isError as h, isCancel as i, connect as j, fulfillPromise as k, callOrWait as l, must as m, noop as n, restarting as o, current as p, mustBeSourceOrSignal as q, resolver as r, start as s, throttle as t, isValue as u, reject as v, isHandled as w, getResult as x, propagateResult as y, CancelError as z };
705
- //# sourceMappingURL=call-or-wait-COAmx32w.mjs.map
705
+ //# sourceMappingURL=call-or-wait-DpJBh_pS.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"call-or-wait-DpJBh_pS.mjs","sources":["../src/results.ts","../src/ambient.ts","../src/internals.ts","../src/chains.ts","../src/tracking.ts","../src/streams.ts","../src/jobutils.ts","../src/call-or-wait.ts"],"sourcesContent":["import { Job, Request } from \"./types.ts\";\n\n/**\n * Resolve a {@link Request} with a value.\n *\n * (For a curried version, see {@link resolver}.)\n *\n * @category Requests and Results\n */\nexport function resolve<T>(request: Request<T>, val: T) { request(\"next\", val); }\n\n/**\n * Reject a {@link Request} with a reason.\n *\n * (For a curried version, see {@link rejecter}.)\n *\n * @category Requests and Results\n */\nexport function reject(request: Request<any>, reason: any) { request(\"throw\", undefined, reason); }\n\n/**\n * Create a callback that will resolve the given {@link Request} with a value.\n *\n * @category Requests and Results\n */\nexport function resolver<T>(request: Request<T>): (val: T) => void { return request.bind(null, \"next\"); }\n\n/**\n * Create a callback that will reject the given {@link Request} with a reason.\n *\n * @category Requests and Results\n */\nexport function rejecter(request: Request<any>): (err: any) => void { return request.bind(null, \"throw\", undefined); }\n\n\n/**\n * A function that does nothing and returns void.\n *\n * @category Stream Consumers\n */\nexport function noop() {}\n\n/**\n * A {@link JobResult} that indicates the job was ended via a return() value.\n *\n * @category Types and Interfaces\n */\nexport type ValueResult<T> = {op: \"next\", val: T, err: undefined};\n\n/**\n * A {@link JobResult} that indicates the job was ended via a throw() or other\n * error.\n *\n * @category Types and Interfaces\n */\nexport type ErrorResult = UnhandledError | HandledError;\n\n/**\n * An {@link ErrorResult} that hasn't yet been \"handled\" (by being passed to an\n * error-specific handler, converted to a promise, given to {@link markHandled},\n * etc.)\n *\n * @category Types and Interfaces\n */\nexport type UnhandledError = {op: \"throw\", val: undefined, err: any};\n\n/**\n * An {@link ErrorResult} that has been marked \"handled\" (by being passed to an\n * error-specific handler, converted to a promise, given to {@link markHandled},\n * etc.)\n *\n * @category Types and Interfaces\n */\nexport type HandledError = {op: \"throw\", val: null, err: any};\n\n/**\n * A {@link JobResult} that indicates the job was canceled by its creator (via\n * end() or restart()).\n *\n * @category Types and Interfaces\n */\nexport type CancelResult = {op: \"cancel\", val: undefined, err: undefined};\n\n/**\n * A result passed to a job's cleanup callbacks, or supplied by its\n * .{@link Job.result result}() method.\n *\n * You can inspect a JobResult using functions like {@link isCancel}(),\n * {@link isError}(), and {@link isValue}(). {@link getResult}() can be used to\n * unwrap the value or throw the error.\n *\n * @category Types and Interfaces\n */\nexport type JobResult<T> = ValueResult<T> | ErrorResult | CancelResult ;\n\nfunction mkResult<T>(op: \"next\", val?: T): ValueResult<T>;\nfunction mkResult(op: \"throw\", val: undefined|null, err: any): ErrorResult;\nfunction mkResult(op: \"cancel\"): CancelResult;\nfunction mkResult<T>(op: string, val?: T, err?: any): JobResult<T> {\n return {op, val, err} as JobResult<T>\n}\n\n/**\n * The {@link JobResult} used to indicate a canceled job.\n *\n * @category Requests and Results\n */\nexport const CancelResult = Object.freeze(mkResult(\"cancel\"));\n\n/**\n * Create a {@link ValueResult} from a value\n *\n * @category Requests and Results\n */\nexport function ValueResult<T>(val: T): ValueResult<T> { return mkResult(\"next\", val); }\n\n/**\n * Create an {@link ErrorResult} from an error\n *\n * @category Requests and Results\n */\nexport function ErrorResult(err: any): UnhandledError { return mkResult(\"throw\", undefined, err); }\n\n/**\n * Returns true if the given result is a {@link CancelResult}.\n *\n * @category Requests and Results\n */\nexport function isCancel(res: JobResult<any> | undefined): res is CancelResult {\n return res === CancelResult;\n}\n\n/**\n * Returns true if the given result is a {@link ValueResult}.\n *\n * @category Requests and Results\n */\nexport function isValue<T>(res: JobResult<T> | undefined): res is ValueResult<T> {\n return res ? res.op === \"next\" : false;\n}\n\n/**\n * Returns true if the given result is a {@link ErrorResult}.\n *\n * @category Requests and Results\n */\nexport function isError(res: JobResult<any> | undefined): res is ErrorResult {\n return res ? res.op === \"throw\" : false;\n}\n\n/**\n * Returns true if the given result is an {@link UnhandledError}.\n *\n * @category Requests and Results\n */\nexport function isUnhandled(res: JobResult<any> | undefined): res is UnhandledError {\n return isError(res) && res.val === undefined;\n}\n\n/**\n * Returns true if the given result is a {@link HandledError} (an\n * {@link ErrorResult} that has been touched by {@link markHandled}).\n *\n * @category Requests and Results\n */\nexport function isHandled(res: JobResult<any> | undefined): res is HandledError {\n return isError(res) && res.val === null;\n}\n\n/**\n * Return the error of an {@link ErrorResult} and mark it as handled. The\n * {@link ErrorResult} is mutated in-place to become a {@link HandledError}.\n *\n * @category Requests and Results\n */\nexport function markHandled(res: ErrorResult): any {\n res.val = null;\n return res.err;\n}\n\n/**\n * Get the return value from a {@link JobResult}, throwing an appropriate error\n * if the result isn't a {@link ValueResult}.\n *\n * @param res The job result you want to unwrap. Must not be undefined!\n *\n * @returns The value if the result is a {@link ValueResult}, or a thrown error\n * if it's an {@link ErrorResult}. A {@link CancelError} is thrown if the job\n * was canceled, or the error in the result is thrown.\n *\n * If the result is an error, it is marked as handled.\n *\n * @category Jobs\n */\nexport function getResult<T>(res: JobResult<T>): T {\n if (isValue(res)) return res.val;\n res.op; // throw if not defined\n fulfillPromise(noop, e => { throw e; }, res);\n}\n\n/**\n * Fulfill a Promise from a {@link JobResult}\n *\n * If the result is a {@link CancelResult}, the promise is rejected with a\n * {@link CancelError}. Otherwise it is resolved or rejected according to the\n * state of the result.\n *\n * @param resolve A value-taking function (first arg to `new Promise` callback)\n *\n * @param reject An error-taking function (second arg to `new Promise` callback)\n *\n * @param res The job result you want to settle the promise with. An error will\n * be thrown if it's undefined.\n *\n * If the result is an error, it is marked as handled.\n *\n * @category Requests and Results\n */\nexport function fulfillPromise<T>(resolve: (v: T) => void, reject: (e: any) => void, res: JobResult<T>) {\n if (isError(res)) reject(markHandled(res));\n else if (isCancel(res)) reject(new CancelError(\"Job canceled\"));\n else resolve(res.val);\n}\n\n/**\n * Propagate a {@link JobResult} to another job\n *\n * If the result is a {@link CancelResult}, the job will throw with a\n * {@link CancelError}. Otherwise it is resolved or rejected according to the\n * state of the result.\n *\n * @param job The job to terminate. If it's already ended, nothing changes: the\n * result is not propagated and the error (if any) is not marked as handled.\n *\n * @param res The job result you want to settle the job with. An error will be\n * thrown if it's undefined. If the result is an error, it is marked as\n * handled.\n *\n * @category Requests and Results\n */\nexport function propagateResult<T>(job: Job<T>, res: JobResult<T>) {\n if (!job.result()) fulfillPromise(job.return.bind(job), job.throw.bind(job), res);\n}\n\n/**\n * Error thrown when waiting for a result from a job that is canceled.\n *\n * If you `await`, `yield *`, `.then()`, `.catch()`, {@link getResult}() or\n * otherwise wait on the result of a job that is canceled, this is the type\n * of error you'll get.\n *\n * @category Errors\n */\nexport class CancelError extends Error {}\n","/**\n * Ambient execution context (for job, resource, and dependency tracking)\n *\n * @internal\n * @module\n */\n\nimport type { Job } from \"./types.ts\";\nimport type { Cell } from \"./cells.ts\";\n\ntype Opt<X> = X | undefined | null;\n\nexport type Context = {\n job: Opt<Job<unknown>>\n cell: Opt<Cell>\n}\n\n/** The current context */\nexport var current: Context = makeCtx();\n\n\n/** Set a new current context, returning the old one */\nexport function swapCtx(future: Context): Context {\n const now = current;\n current = future;\n return now\n}\n\nvar freelist = [] as Context[];\n\n/** Get a fresh context object (either by creation or recycling) */\nexport function makeCtx(\n job?: Context[\"job\"],\n cell?: Context[\"cell\"],\n): Context {\n if (freelist && freelist.length) {\n const s = freelist.pop()!;\n s.job = job;\n s.cell = cell;\n return s;\n }\n return {job, cell};\n}\n\n/** Put a no-longer-needed context object on the recycling heap */\nexport function freeCtx(s: Context) {\n s.job = s.cell = null;\n freelist.push(s);\n}\n\n","/**\n * Provide access to certain internals (for testing use only)\n *\n * @module\n */\n\nimport { makeCtx } from \"./ambient.ts\";\nimport { batch } from \"./scheduling.ts\";\nimport { defer } from \"./defer.ts\";\nimport { Job } from \"./types.ts\";\n\nexport const\n /** Jobs' asyncCatch handlers: in a map because few jobs will have them */\n catchers = new WeakMap<Job, (this: Job, err: any) => unknown>(),\n\n /** Default error handler for the `detached` job */\n defaultCatch = (e: any) => { Promise.reject(e); }\n;\n\n/** A null context (no job/observer) for cleanups to run in */\nexport const nullCtx = makeCtx();\n\n/** Jobs' owners (parents) - uses a map so child jobs can't directly access them */\nexport const owners = new WeakMap<Job, Job>();\n\n/** Streams that need resuming */\nexport const pulls = /* @__PURE__ */ batch<{ doPull(): void; }>(pulls => {\n for (const conn of pulls) { pulls.delete(conn); conn.doPull(); }\n}, defer);\n","import { DisposeFn } from \"./types.ts\";\n\n/**\n * A counted, double-ended queue with the ability to undo insertions (even out\n * of order).\n *\n * @category Chains\n */\nexport type Chain<T, U=any> = Node<T, number, U>;\n\n/**\n * Create a new Chain\n *\n * @category Chains\n */\nexport function chain<T, U=DisposeFn>(): Chain<T, U> { return link<number, U>(0, undefined, undefined); }\n\n/**\n * Recycle a chain entirely - only safe if no references to it remain anywhere!\n */\nexport function recycle(c: Chain<any>) {\n while (c.v) unlink(c, c.n);\n c.u = undefined;\n unlink(c, c);\n}\n\n/**\n * Unshift a value onto the front of the chain\n *\n * @category Chains\n */\nexport function unshift<T>(c: Chain<T>, v: T) { ++c.v; link(v, c.n, c); }\n\n/**\n * Unshift a value onto the front of the chain, returning an undo callback. The\n * callback can be invoked to remove the value from the chain at any time, even\n * after other values have been added or removed. There is no effect if the\n * callback is run more than once, or if the value has already been removed.\n *\n * @category Chains\n */\nexport function unshiftCB<T>(c: Chain<T>, v: T) { ++c.v; return unlinker(c, link(v, c.n, c)); }\n\n/**\n * Push a value onto the end of the chain\n *\n * @category Chains\n */\nexport function push<T>(c: Chain<T>, v: T) { ++c.v; link(v, c, c.p); }\n\n/**\n * Push a value onto the end of the chain, returning an undo callback. The\n * callback can be invoked to remove the value from the chain at any time, even\n * after other values have been added or removed. There is no effect if the\n * callback is run more than once, or if the value has already been removed.\n *\n * @category Chains\n */\nexport function pushCB<T>(c: Chain<T>, v: T) { ++c.v; return unlinker(c, link(v, c, c.p)); }\n\n/**\n * Return true if the chain is empty, or is null/undefined\n *\n * @category Chains\n */\nexport function isEmpty(c: Chain<any> | null | undefined) { return !c || c.v === 0; }\n\n/**\n * Return the number of items in the chain, or 0 if it's null/undefined\n *\n * @category Chains\n */\nexport function qlen(c: Chain<any> | null | undefined) { return c ? c.v : 0; }\n\n/**\n * Remove a value from the end of the chain, returning it\n *\n * @category Chains\n */\nexport function pop<T>(c: Chain<T>) { if (qlen(c)) return unlink(c, c.p); }\n\n/**\n * Remove a value from the front of the chain, returning it\n *\n * @category Chains\n */\nexport function shift<T>(c: Chain<T>) { if (qlen(c)) return unlink(c, c.n); }\n\n/** A node in a chain */\nclass Node<T, V=T, U=DisposeFn> {\n /** The next node (or the start node if this is a chain head) */\n n: Node<T> = this as Node<T, any>;\n /** The previous node (or the end node if this is a chain head) */\n p: Node<T> = this as Node<T, any>;\n /** The value held by the node (or the chain length if this is a chain head) */\n v: V = undefined;\n /** The most recently created undo callback for this node */\n u: U = undefined;\n}\n\n/** Recycling list for chain nodes, to reduce constructor/alloc overhead */\nvar free: Node<any,any,any>;\n\n/** Create (or reuse) a node with a given value, inserting it between two nodes in a chain */\nfunction link<T,U=DisposeFn>(v: T, n: Node<T, any, any>, p: Node<T, any, any>): Node<T,T,U> {\n let node: Node<T, T, any> = free;\n if (node) {\n free = node.n;\n node.n = n || node;\n node.p = p || node;\n } else {\n node = new Node<T, T, U>;\n if (n) node.n = n;\n if (p) node.p = p;\n }\n node.v = v;\n node.n.p = node;\n node.p.n = node;\n return node;\n}\n\n/** Unlink a node from a chain and recycle it, returning the value it held */\nfunction unlink<T>(c: Chain<any>, node: Node<T>) {\n --c.v;\n var v = node.v, u = node.u;\n node.n && (node.n.p = node.p);\n node.p && (node.p.n = node.n);\n node.u = node.v = node.p = undefined;\n node.n = free; free = node;\n if (u) u(); // drop refs to node+chain\n return v;\n}\n\n/**\n * Return an undo/remove callback that will run at most once and is a no-op if the\n * node was already removed. If called more than once on the same node while\n * it's in the same chain, it returns the same callback. ()\n */\nfunction unlinker(chain: Chain<any>, node: Node<any>) {\n let u = (node.u ||= () => {\n if (u) {\n // If the node's undo callback is this callback, then it's safe to remove;\n // otherwise, the node has already been removed and/or recycled for use in\n // a different chain (or a different value in this one!)\n if (u === node.u) unlink(chain, node);\n u = chain = node = undefined;\n }\n })\n return u;\n}\n","import { makeCtx, current, freeCtx, swapCtx } from \"./ambient.ts\";\nimport { catchers, defaultCatch, nullCtx, owners } from \"./internals.ts\";\nimport { CleanupFn, Job, Request, Yielding, Suspend, PlainFunction, StartFn, OptionalCleanup, JobIterator, RecalcSource, StartObj } from \"./types.ts\";\nimport { defer } from \"./defer.ts\";\nimport { JobResult, ErrorResult, CancelResult, isCancel, ValueResult, isError, isValue, noop, markHandled, isUnhandled, propagateResult } from \"./results.ts\";\nimport { rejecter, resolver, getResult, fulfillPromise } from \"./results.ts\";\nimport { Chain, chain, isEmpty, pop, push, pushCB, qlen, recycle, unshift } from \"./chains.ts\";\nimport { Stream, Sink, Inlet, Connection } from \"./streams.ts\";\nimport { GeneratorBase, apply } from \"./utils.ts\";\nimport { isFunction } from \"./utils.ts\";\n\n/**\n * Return the currently-active Job, or throw an error if none is active.\n *\n * (You can check if a job is active first using {@link isJobActive}().)\n *\n * @category Jobs\n */\nexport function getJob<T=unknown>() {\n const job = current.job || current.cell?.getJob();\n if (job) return job as Job<T>;\n throw new Error(\"No job is currently active\");\n}\n\n/** RecalcSource factory for jobs (so you can wait on a job result in a signal or rule) */\nfunction recalcJob(job: Job<any>): RecalcSource { return (cb => { current.job.must(job.release(cb)); }); }\n\nfunction runChain<T>(res: JobResult<T>, cbs: Chain<CleanupFn<T>>): undefined {\n while (qlen(cbs)) try { pop(cbs)(res); } catch (e) { detached.asyncThrow(e); }\n cbs && recycle(cbs);\n return undefined;\n}\n\n// The set of jobs whose callbacks need running during an end() sweep\nvar inProcess = new Set<_Job<any>>;\n\nclass _Job<T> implements Job<T> {\n /** @internal */\n static create<T>(parent?: Job, stop?: CleanupFn): Job<T> {\n const job = new _Job<T>;\n if (parent || stop) {\n job.must((parent ||= getJob()).release(stop || job.end));\n owners.set(job, parent);\n }\n return job;\n }\n\n do(cleanup: CleanupFn<T>): this {\n unshift(this._chain(), cleanup);\n return this;\n }\n\n onError(cb: (err: any) => unknown): this {\n return this.do(r => { if (isError(r)) cb(markHandled(r)); });\n }\n\n onValue(cb: (val: T) => unknown): this {\n return this.do(r => { if (isValue(r)) cb(r.val); });\n }\n\n onCancel(cb: () => unknown): this {\n return this.do(r => { if (isCancel(r)) cb(); });\n }\n\n result(): JobResult<T> | undefined {\n // If we're done, we're done; otherwise make signals/rules reading this\n // recalc when we're done (handy for rendering \"loading\" states).\n return this._done || current.cell?.recalcWhen(this, recalcJob) || undefined;\n }\n\n get [Symbol.toStringTag]() { return \"Job\"; }\n\n end = () => {\n const res = (this._done ||= CancelResult), cbs = this._cbs;\n // if we have an unhandled error, fall through to queued mode for later\n // re-throw; otherwise, if there aren't any callbacks we're done here\n if (!cbs && !isUnhandled(res)) return;\n\n const ct = inProcess.size, old = swapCtx(nullCtx);;\n // Put a placeholder on the queue if it's empty\n if (!ct) inProcess.add(null);\n\n // Give priority to the release() chain so we get breadth-first flagging\n // of all child jobs as canceled immediately\n if (cbs && cbs.u) cbs.u = runChain(res, cbs.u);\n\n // Put ourselves on the queue *after* our children, so their cleanups run first\n inProcess.add(this);\n\n // if the queue wasn't empty, there's a loop above us that will run our must/do()s\n if (ct) { swapCtx(old); return; }\n\n // don't need the placeholder any more\n inProcess.delete(null);\n\n // Queue was empty, so it's up to us to run everybody's must/do()s\n for (const item of inProcess) {\n if (item._cbs) item._cbs = runChain(item._done, item._cbs);\n inProcess.delete(item);\n if (isUnhandled(item._done)) item.throw(markHandled(item._done));\n }\n swapCtx(old);\n }\n\n restart() {\n if (!this._done && inProcess.size) {\n // if a tree of jobs is ending right now, we need to start\n // a new stack so that when we return, all our children's\n // callbacks will have finished running first.\n const old = inProcess;\n inProcess = new Set;\n this.end();\n inProcess = old;\n } else {\n this._end(CancelResult);\n }\n this._done = undefined;\n promises.delete(this); // don't reuse any now-cancelled promise!\n return this;\n }\n\n _end(res: JobResult<T>) {\n if (this._done) throw new Error(\"Job already ended\");\n if (this !== detached) this._done = res;\n this.end();\n return this;\n }\n\n throw(err: any) {\n if (this._done) {\n (owners.get(this) || detached).asyncThrow(err);\n return this;\n }\n return this._end(ErrorResult(err));\n }\n\n return(val: T) { return this._end(ValueResult(val)); }\n\n then<T1=T, T2=never>(\n onfulfilled?: (value: T) => T1 | PromiseLike<T1>,\n onrejected?: (reason: any) => T2 | PromiseLike<T2>\n ): Promise<T1 | T2> {\n return nativePromise(this).then(onfulfilled, onrejected);\n }\n\n catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<T | TResult> {\n return nativePromise(this).catch(onrejected);\n }\n\n finally(onfinally?: () => void): Promise<T> {\n return nativePromise(this).finally(onfinally);\n }\n\n *[Symbol.iterator](): JobIterator<T> {\n if (this._done) {\n return getResult(this._done);\n } else return yield (req: Request<T>) => {\n // XXX should this be a release(), so if the waiter dies we\n // don't bother? The downside is that it'd have to be mutual and\n // the resume is a no-op anyway in that case.\n this.do(res => fulfillPromise(resolver(req), rejecter(req), res));\n }\n }\n\n start<T>(fn?: StartFn<T> | StartObj<T>): Job<T>;\n start<T, This>(ctx: This, fn: StartFn<T, This>): Job<T>;\n start<T, This>(fnOrCtx: StartFn<T> | StartObj<T>|This, fn?: StartFn<T, This>) {\n if (!fnOrCtx) return makeJob(this);\n let init: StartFn<T, This>, result: StartObj<T> | OptionalCleanup;\n if (isFunction(fn)) {\n init = fn.bind(fnOrCtx as This);\n } else if (isFunction(fnOrCtx)) {\n init = fnOrCtx as StartFn<T, This>;\n } else if (fnOrCtx instanceof _Job) {\n return fnOrCtx;\n } else {\n result = fnOrCtx as StartObj<T>;\n }\n const job = makeJob<T>(this);\n try {\n if (init) result = job.run(init as StartFn<T>, job);\n if (result != null) {\n if (isFunction(result)) {\n job.must(result);\n } else if (result instanceof GeneratorBase) {\n job.run(runGen<T>, result as Yielding<T>, job);\n } else if (result instanceof _Job) {\n if (result !== job) result.do(res => propagateResult(job, res));\n } else if (result instanceof Promise) {\n // Duplicated because this will be monomorphic or low-poly,\n // but next branch will always be megamorphic\n (result as Promise<T>).then(\n v => { job.result() || job.return(v); },\n e => { job.result() || job.throw(e); }\n );\n } else if (isFunction((result as Promise<T>).then)) {\n (result as Promise<T>).then(\n v => { job.result() || job.return(v); },\n e => { job.result() || job.throw(e); }\n );\n } else if (\n isFunction((result as Yielding<T>)[Symbol.iterator]) &&\n typeof result !== \"string\"\n ) {\n job.run(runGen<T>, result as Yielding<T>, job);\n } else {\n throw new TypeError(\"Invalid value/return for start()\");\n }\n }\n return job;\n } catch(e) {\n job.end();\n throw e;\n }\n }\n\n connect<T>(src: Stream<T>, sink: Sink<T>, inlet?: Inlet): Connection {\n return this.start(job => void src(sink, job, inlet));\n }\n\n protected constructor() {};\n\n run<F extends PlainFunction>(fn: F, ...args: Parameters<F>): ReturnType<F> {\n const old = swapCtx(makeCtx(this));\n try { return fn(...args); } finally { freeCtx(swapCtx(old)); }\n }\n\n bind<F extends (...args: any[]) => any>(fn: F): F {\n const job = this;\n return <F> function (this: any) {\n const old = swapCtx(makeCtx(job));\n try { return apply(fn, this, arguments); } finally { freeCtx(swapCtx(old)); }\n }\n }\n\n must(cleanup?: OptionalCleanup) {\n if (isFunction(cleanup)) push(this._chain(), cleanup);\n return this;\n }\n\n release(cleanup: CleanupFn): () => void {\n if (this === detached) return noop;\n let cbs = this._chain();\n if (!this._done || cbs.u) cbs = cbs.u ||= chain();\n return pushCB(cbs, cleanup);\n }\n\n asyncThrow(err: any) {\n try {\n (catchers.get(this) || this.throw).call(this, err);\n } catch (e) {\n // Don't allow a broken handler to stay on the job\n if (this === detached) catchers.set(this, defaultCatch); else catchers.delete(this);\n const catcher = catchers.get(this) || this.throw;\n catcher.call(this, err);\n catcher.call(this, e); // also report the broken handler\n }\n return this;\n }\n\n asyncCatch(handler: ((this: Job, err: any) => unknown) | null): this {\n if (isFunction(handler)) catchers.set(this, handler);\n else if (handler === null) catchers.delete(this);\n return this;\n }\n\n protected _done: JobResult<T> = undefined;\n\n // Chain whose .u stores a second chain for `release()` callbacks\n protected _cbs: Chain<CleanupFn<T>, Chain<CleanupFn<T>>> = undefined;\n protected _chain() {\n if (this === detached) this.end()\n if (this._done && isEmpty(this._cbs)) defer(this.end);\n return this._cbs ||= chain();\n }\n}\n\nconst promises = new WeakMap<Job<any>, Promise<any>>();\n\n/**\n * Obtain a native promise for a job\n *\n * While jobs have the same interface as native promises, there are occasionally\n * reasons to just use one directly. (Like when Uneventful uses this function\n * to implement jobs' promise methods!)\n *\n * @param job The job to get a native promise for.\n *\n * @returns A {@link Promise} that resolves or rejects according to whether the\n * job returns or throws. If the job is canceled, the promise is rejected with\n * a {@link CancelError}.\n *\n * @category Jobs\n */\nexport function nativePromise<T>(job: Job<T>): Promise<T> {\n if (!promises.has(job)) {\n promises.set(job, new Promise((res, rej) => {\n const toPromise = (fulfillPromise<T>).bind(null, res, rej);\n if (job.result()) toPromise(job.result()); else job.do(toPromise);\n }));\n }\n return promises.get(job);\n}\n\n/**\n * Return a new {@link Job}. If *either* a parent parameter or stop function\n * are given, the new job is linked to the parent.\n *\n * @param parent The parent job to which the new job should be attached.\n * Defaults to the currently-active job if none given (assuming a stop\n * parameter is provided).\n *\n * @param stop The function to call to destroy the nested job. Defaults to the\n * {@link Job.end} method of the new job if none is given (assuming a parent\n * parameter is provided).\n *\n * @returns A new job. The job is linked/nested if any arguments are given,\n * or a detached (parentless) job otherwise.\n *\n * @category Jobs\n */\nexport const makeJob: <T>(parent?: Job, stop?: CleanupFn) => Job<T> = _Job.create;\n\n/**\n * A special {@link Job} with no parents, that can be used to create standalone\n * jobs. detached.start() returns a new detached job, detached.run() can be\n * used to run code that expects to create a child job, and detached.bind() can\n * wrap a function to work without a parent job.\n *\n * (Note that such `detached` child jobs *must* exit themselves or be stopped\n * explicitly from outside, or else they may \"run\" forever, never running their\n * cleanup callbacks. Unlike other jobs, they don't end when their parent does\n * because the `detached` job never \"ends\".)\n *\n * The detached job has a few special features and limitations:\n *\n * - It can't be ended, thrown, return()ed, etc. -- you'll get an error\n *\n * - It can't have any cleanup functions added: no do, must, onError, etc., and\n * thus also can't have any native promise, abort signal, etc. used. You can\n * call its release() method, but nothing will actually be registered and the\n * returned callback is a no-op.\n *\n * - Unhandled errors from jobs without parents (and errors from *any* job's\n * cleanup functions) are sent to the detached job for handling. This means\n * whatever you set as the detached job's .{@link Job.asyncCatch asyncCatch}()\n * handler will receive them. (Its default is Promise.reject, causing an\n * unhandled promise rejection.)\n *\n * @category Jobs\n */\nexport const detached = makeJob();\n(detached as any).end = () => { throw new Error(\"Can't do that with the detached job\"); }\ndetached.asyncCatch(defaultCatch);\n\nfunction runGen<R>(g: Yielding<R>, job: Job<R>) {\n let it = g[Symbol.iterator](), running = true, ctx = makeCtx(job), ct = 0;\n let done = ctx.job.release(() => {\n job = undefined;\n ++ct; // disable any outstanding request(s)\n // XXX this should be deferred to cleanup phase, or must() instead of release\n // (release only makes sense here if you can run more than one generator in a job)\n step(\"return\", undefined);\n });\n // Start asynchronously\n defer(() => { running = false; step(\"next\", undefined); });\n\n function step(method: \"next\" | \"throw\" | \"return\", arg: any): void {\n if (!it) return;\n // Don't resume a job while it's running\n if (running) {\n return defer(step.bind(null, method, arg));\n }\n const old = swapCtx(ctx);\n try {\n running = true;\n try {\n for(;;) {\n ++ct;\n const {done, value} = it[method](arg);\n if (done) {\n job && job.return(value);\n job = undefined;\n break;\n } else if (!isFunction(value)) {\n method = \"throw\";\n arg = new TypeError(\"Jobs must yield functions (or yield* Yielding<T>s)\");\n continue;\n } else {\n let called = false, returned = false, count = ct;\n (value as Suspend<any>)((op, val, err) => {\n if (called) return; else called = true;\n method = op; arg = op === \"next\" ? val : err;\n if (returned && count === ct) step(op, arg);\n });\n returned = true;\n if (!called) return;\n }\n }\n } catch(e) {\n it = job = undefined;\n ctx.job.throw(e);\n }\n // Iteration is finished; disconnect from job\n it = undefined;\n done?.();\n done = undefined;\n } finally {\n swapCtx(old);\n running = false;\n }\n }\n}\n","import { pulls } from \"./internals.ts\";\nimport { DisposeFn, Job } from \"./types.ts\";\nimport { getJob } from \"./tracking.ts\";\nimport { current } from \"./ambient.ts\";\nimport type { Signal } from \"./signals.ts\"; // needed for documentation links\n\n/**\n * A backpressure controller: returns true if downstream is ready to accept\n * data.\n *\n * @param cb (optional) - a callback to run when the downstream consumer wishes\n * to resume event production (i.e., when a sink calls\n * {@link Throttle.resume}()). The callback is automatically unregistered when\n * invoked, so the producer must re-register it after each call if it wishes to\n * keep being called.\n *\n * @category Types and Interfaces\n */\nexport type Backpressure = (cb?: () => any) => boolean\n\n\n/**\n * Create a backpressure control function for the given connection\n *\n * @category Stream Producers\n */\nexport function backpressure(inlet: Inlet = defaultInlet): Backpressure {\n const job = getJob();\n return (cb?: Flush) => {\n if (!job.result() && inlet.isOpen()) {\n if (cb) inlet.onReady(cb, job);\n return inlet.isReady();\n }\n return false;\n }\n}\n\n/**\n * Control backpressure for listening streams. This interface is the API\n * internal to the implementation of {@link backpressure}(). Unless you're\n * implementing a backpressurable stream yourself, see the {@link Throttle}\n * interface instead.\n *\n * @category Types and Interfaces\n */\nexport interface Inlet {\n /** Is the main connection open? (i.e. is the creating job not closed yet?) */\n isOpen(): boolean\n\n /** Is the connection ready to receive data? */\n isReady(): boolean\n\n /**\n * Register a callback to produce more data when the inlet is resumed\n * (The callback is unregistered if the supplied job ends.)\n */\n onReady(cb: () => any, job: Job): this;\n}\n\n/**\n * Control backpressure for listening streams\n *\n * Obtain instances via {@link throttle}(), then pass them into the appropriate\n * stream-consuming API. (e.g. {@link connect}).\n *\n * @category Types and Interfaces\n */\nexport interface Throttle extends Inlet {\n /** Set inlet status to \"paused\". */\n pause(): void;\n\n /**\n * Un-pause, and iterate backpressure-able sources' onReady callbacks to\n * resume sending immediately. (i.e., synchronously!)\n */\n resume(): void;\n}\n\n/**\n * A Connection is a job that returns void when the connected stream ends\n * itself. If the stream doesn't end itself (e.g. it's an event listener), the\n * job will never return, and only end with a cancel or throw.\n *\n * @category Types and Interfaces\n */\nexport type Connection = Job<void>;\n\n/**\n * A Source is a function that can be called to arrange for data to be\n * produced and sent to a {@link Sink} function for consumption, until the\n * associated {@link Connection} is closed (either by the source or the sink,\n * e.g. if the sink doesn't want more data or the source has no more to send).\n *\n * If the source is a backpressurable stream, it can use the (optional) supplied\n * inlet (usually a {@link throttle}()) to rate-limit its output.\n *\n * A producer function *must* return the special {@link IsStream} value, so\n * TypeScript can tell what functions are usable as sources. (Otherwise any\n * void function with no arguments would appear to be usable as a source!)\n *\n * @category Types and Interfaces\n */\nexport interface Source<T> {\n /** Subscribe sink to receive values */\n (sink: Sink<T>, conn?: Connection, inlet?: Throttle | Inlet): typeof IsStream;\n}\n\n/**\n * An uneventful stream is either a {@link Source} or a {@link SignalSource}.\n * (Signals actually implement the {@link Source} interface as an overload, but\n * TypeScript gets confused about that sometimes, so we generally declare our\n * stream *inputs* as `Stream<T>` and our stream *outputs* as {@link Source}, so\n * that TypeScript knows what's what.\n *\n * @category Types and Interfaces\n */\nexport type Stream<T> = Source<T> | SignalSource<T>;\n\n/**\n * The call signatures implemented by signals. (They can be used as sources, or\n * called with no arguments to return a value.)\n *\n * This type is needed because TypeScript won't infer the overloads of\n * {@link Signal} correctly otherwise. (Specifically, it won't allow it to be\n * used as a zero-agument function.)\n *\n * @category Types and Interfaces\n*/\nexport type SignalSource<T> = Source<T> & {\n /** A signal object can be called to get its current value */\n (): T\n}\n\n/**\n * A specially-typed string used to verify that a function supports uneventful's\n * streaming protocol. Return it from a function to implement the\n * {@link Source} type.\n *\n * @category Types and Interfaces\n */\nexport const IsStream = \"uneventful/is-stream\" as const;\n\n/**\n * A `Sink` is a function that receives data from a {@link Stream}.\n *\n * @category Types and Interfaces\n */\nexport type Sink<T> = (val: T) => void;\n\n/**\n * A `Transformer` is a function that takes one stream and returns another,\n * possibly one that produces data of a different type. Most operator functions\n * return a transformer, allowing them to be combined via {@link pipe}().\n *\n * @category Types and Interfaces\n */\nexport type Transformer<T, V=T> = (input: Stream<T>) => Source<V>;\n\ntype Flush = () => any\n\n\n/**\n * Subscribe a sink to a stream, returning a nested job. (Shorthand for\n * .{@link Job.connect connect}(...) on the active job.)\n *\n * @param src An event source or signal\n * @param sink A callback that will receive the events\n * @param inlet Optional - a {@link throttle}() to control backpressure\n *\n * @returns A job that can be aborted to end the subscription, and which will\n * end naturally (with a void return or error) if the stream ends itself.\n *\n * @category Stream Consumers\n */\nexport function connect<T>(src: Stream<T>, sink: Sink<T>, inlet?: Throttle | Inlet): Connection {\n return getJob().connect(src, sink, inlet);\n}\n\n/**\n * Create a backpressure controller for a stream. Pass it to one or more\n * sources you're connecting to, and if they support backpressure they'll\n * respond when you call its .pause() and .resume() methods.\n *\n * @param job - Optional: a job that controls readiness. (The throttle will\n * pause indefinitely when the job ends.) Defaults to the currently-active job,\n * but unlike most such defaults, it won't throw if no job is active.\n *\n * @category Stream Consumers\n */\nexport function throttle(job: Job = current.job): Throttle {\n return new _Throttle(job);\n}\n\nclass _Throttle implements Throttle {\n /** @internal */\n protected _callbacks: Map<Flush, DisposeFn> = undefined;\n\n /** @internal */\n constructor(protected _job?: Job) {}\n\n isOpen(): boolean { return !this._job?.result(); }\n\n /** Is the connection ready to receive data? */\n isReady(): boolean { return this.isOpen() && this._isReady; }\n\n _isReady = true;\n _isPulling = false;\n\n onReady(cb: Flush, job: Job) {\n if (!this.isOpen()) return this;\n const _callbacks = (this._callbacks ||= new Map);\n const unlink = job.release(() => _callbacks.delete(cb));\n if (this.isReady() && this && !_callbacks.size) {\n pulls.add(this);\n }\n _callbacks.set(cb, unlink);\n return this;\n }\n\n pause() { this._isReady = false; return this; }\n\n doPull() {\n if (this._isPulling) return;\n const {_callbacks} = this;\n if (!_callbacks?.size) return;\n this._isPulling = true;\n try {\n for(let [cb, unlink] of _callbacks) {\n if (!this.isReady()) break; // we're done\n unlink()\n _callbacks.delete(cb);\n cb() // XXX error handling?\n }\n } finally {\n this._isPulling = false;\n }\n }\n\n resume() {\n if (this.isOpen()) {\n this._isReady = true;\n this.doPull();\n }\n }\n}\n\nconst defaultInlet: Inlet = throttle();\n\n/**\n * Pipe a stream (or anything else) through a series of single-argument\n * functions/operators\n *\n * e.g. the following creates a stream that outputs 4 and then 6:\n *\n * ```ts\n * pipe(fromIterable([1,2,3,4]), skip(1), take(2), map(x => x*2))\n * ```\n *\n * The first argument to pipe() can be any value, but all other arguments must\n * be functions. The value is passed to the first function, and then the result\n * is passed to the next function in turn, until all provided functions have\n * been called with the result of the previous function. The return value is\n * the last result, or the original value if no functions were given.\n *\n * The underlying implementation of pipe() works with any number of arguments,\n * but due to TypeScript limitations we only have typing defined for a max of 9\n * functions (10 arguments total). If you need more than 9 functions, you can\n * stack some of them with {@link compose}(), e.g.:\n *\n * ```typescript\n * pipe(\n * aStream,\n * compose(op1, op2, ...),\n * compose(op10, op11, ...),\n * compose(op19, ...),\n * ...\n * )\n * ```\n *\n * @category Stream Operators\n */\nexport function pipe<A,B,C,D,E,F,G,H,I,J>(input: A, ...fns: Chain9<A,J,B,C,D,E,F,G,H,I>): J\nexport function pipe<A,B,C,D,E,F,G,H,I> (input: A, ...fns: Chain8<A,I,B,C,D,E,F,G,H>): I\nexport function pipe<A,B,C,D,E,F,G,H> (input: A, ...fns: Chain7<A,H,B,C,D,E,F,G>): H\nexport function pipe<A,B,C,D,E,F,G> (input: A, ...fns: Chain6<A,G,B,C,D,E,F>): G\nexport function pipe<A,B,C,D,E,F> (input: A, ...fns: Chain5<A,F,B,C,D,E>): F\nexport function pipe<A,B,C,D,E> (input: A, ...fns: Chain4<A,E,B,C,D>): E\nexport function pipe<A,B,C,D> (input: A, ...fns: Chain3<A,D,B,C>): D\nexport function pipe<A,B,C> (input: A, ...fns: Chain2<A,C,B>): C\nexport function pipe<A,B> (input: A, ...fns: Chain1<A,B>): B\nexport function pipe<A> (input: A): A\nexport function pipe(input: any, ...fns: Array<(v: any) => any>): any;\nexport function pipe<A,X>(): X {\n var v = arguments[0];\n for (var i=1; i<arguments.length; i++) v = arguments[i](v);\n return v;\n}\n\n/**\n * Compose a series of single-argument functions/operators in application order.\n * (This is basically a deferred version of {@link pipe}().) For example:\n *\n * ```ts\n * const func = compose(skip(1), take(2), map(x => x*2));\n * const stream_4_6 = func(fromIterable([1,2,3,4])); // stream that outputs 4, 6\n * ```\n *\n * As with `pipe()`, the declared typings only support composing up to 9\n * functions at once; if you need more you'll need to nest calls to `compose()`\n * (i.e. passing the result of a `compose()` as an argument to another\n * `compose()` call.)\n *\n * @returns A function taking the same type as the first input function,\n * returning the same type as the last input function.\n *\n * @category Stream Operators\n */\nexport function compose<A,B,C,D,E,F,G,H,I,J>(...fns: Chain9<A,J,B,C,D,E,F,G,H,I>): (a: A) => J\nexport function compose<A,B,C,D,E,F,G,H,I> (...fns: Chain8<A,I,B,C,D,E,F,G,H>): (a: A) => I\nexport function compose<A,B,C,D,E,F,G,H> (...fns: Chain7<A,H,B,C,D,E,F,G>): (a: A) => H\nexport function compose<A,B,C,D,E,F,G> (...fns: Chain6<A,G,B,C,D,E,F>): (a: A) => G\nexport function compose<A,B,C,D,E,F> (...fns: Chain5<A,F,B,C,D,E>): (a: A) => F\nexport function compose<A,B,C,D,E> (...fns: Chain4<A,E,B,C,D>): (a: A) => E\nexport function compose<A,B,C,D> (...fns: Chain3<A,D,B,C>): (a: A) => D\nexport function compose<A,B,C> (...fns: Chain2<A,C,B>): (a: A) => C\nexport function compose<A,B> (...fns: Chain1<A,B>): (a: A) => B\nexport function compose<A> (): (a: A) => A\nexport function compose(...fns: ((v:any)=>any)[]) {\n return (val:any) => (pipe as any)(val, ...fns);\n}\n\ntype Chain1<A,R> = [(v: A) => R];\ntype Chain2<A,R,B> = [...Chain1<A,B>, ...Chain1<B,R>];\ntype Chain3<A,R,B,C> = [...Chain1<A,B>, ...Chain2<B,R,C>];\ntype Chain4<A,R,B,C,D> = [...Chain1<A,B>, ...Chain3<B,R,C,D>];\ntype Chain5<A,R,B,C,D,E> = [...Chain1<A,B>, ...Chain4<B,R,C,D,E>];\ntype Chain6<A,R,B,C,D,E,F> = [...Chain1<A,B>, ...Chain5<B,R,C,D,E,F>];\ntype Chain7<A,R,B,C,D,E,F,G> = [...Chain1<A,B>, ...Chain6<B,R,C,D,E,F,G>];\ntype Chain8<A,R,B,C,D,E,F,G,H> = [...Chain1<A,B>, ...Chain7<B,R,C,D,E,F,G,H>];\ntype Chain9<A,R,B,C,D,E,F,G,H,I> = [...Chain1<A,B>, ...Chain8<B,R,C,D,E,F,G,H,I>];\n\n/**\n * Pass subscriber into a stream (or any arguments into any other function).\n *\n * This utility is mainly here for uses like:\n *\n * - `pipe(src, into(sink))`,\n * - `pipe(src, into(sink, conn))`,\n * - `pipe(src, into(restarting(sink)))`, etc.\n *\n * but can also be used for argument currying generally.\n *\n * @param args The arguments to pass to the stream (or other function)\n *\n * @returns a function that takes another function and calls it with the given args.\n *\n * @category Stream Consumers\n */\nexport function into<In extends any[], Out>(...args: In): (src: (...args: In) => Out) => Out {\n return src => src(...args);\n}\n","import { current, freeCtx, makeCtx, swapCtx } from \"./ambient.ts\";\nimport { getJob, makeJob } from \"./tracking.ts\";\nimport { AnyFunction, CleanupFn, Job, OptionalCleanup, StartFn, StartObj, Yielding } from \"./types.ts\";\nimport { apply } from \"./utils.ts\";\n\n/**\n * Add a cleanup function to the active job. Non-function values are ignored.\n * Equivalent to calling .{@link Job.must must}() on the current job. (See\n * {@link Job.must}() for more details.)\n *\n * @category Jobs\n */\nexport function must(cleanup?: OptionalCleanup): void {\n getJob().must(cleanup);\n}\n\n/**\n * Start a nested job within the currently-active job. (Shorthand for\n * calling .{@link Job.start start}(...) on the active job.)\n *\n * This function can be called with zero, one, or two arguments:\n *\n * - When called with zero arguments, the new job is returned without any other\n * initialization.\n *\n * - When called with one argument that's a function (either a {@link SyncStart}\n * or {@link AsyncStart}): the function is run inside the new job and receives\n * it as an argument. It can return a {@link Yielding} iterator (such as a\n * generator or job), a promise, or void. A returned iterator or promise will\n * be treated as if the method was called with that to begin with; a returned\n * job will be awaited and its result transferred to the new job\n * asynchronously. A returned function will be added to the job via `must()`.\n *\n * - When called with one argument that's a {@link Yielding} iterator (such as a\n * generator or an existing job): it's attached to the new job and executed\n * asynchronously. (Starting in the next available microtask.)\n *\n * - When called with one argument that's a Promise, it's converted to a job\n * that will end when the promise settles. The resulting job is returned.\n *\n * - When called with two arguments -- a \"this\" object and a function -- it\n * works the same as one argument that's a function, except the function is\n * bound to the supplied \"this\" before being called.\n *\n * This last signature is needed because you can't make generator arrows in JS\n * yet: if you want to start() a generator function bound to the current\n * `this`, you'll want to use `.start(this, function*() { ...whatever })`.\n *\n * (Note, however, that TypeScript and/or VSCode may require that you give\n * such a function an explicit `this` parameter (e.g. `.start(this, function\n * *(this) {...}));`) in order to correctly infer types inside a generator\n * function.)\n *\n * In any of the above cases, if a supplied function throws an error while\n * starting, the new job will be ended, and the error synchronously re-thrown.\n *\n * @returns the created {@link Job}\n *\n * @category Jobs\n */\nexport function start<T>(init?: StartFn<T> | StartObj<T>): Job<T>;\n\n/**\n * The two-argument variant of start() allows you to pass a \"this\" object that\n * will be bound to the initialization function. (It's mostly useful for\n * generator functions, since generator arrows aren't a thing yet.)\n */\nexport function start<T, This>(thisArg: This, fn: StartFn<T, This>): Job<T>;\nexport function start<T, This>(init: StartFn<T>|StartObj<T>|This, fn?: StartFn<T, This>) {\n return getJob().start(init as This, fn);\n}\n\n/**\n * Is there a currently active job? (i.e., can you safely use {@link must}(),\n * or {@link getJob}() right now?)\n *\n * @category Jobs\n */\nexport function isJobActive() { return !!current.job; }\n\n\nconst timers = new WeakMap<Job,\n ReturnType<typeof setTimeout> | // current timeout\n undefined | // no timeout set since job was last restarted (if ever)\n null // current timeout is 0, aka explicit no-timeout\n>();\n\n/**\n * Set the cancellation timeout for a job.\n *\n * When the timeout is reached, the job is canceled (throwing\n * {@link CancelError} to any waiting promises or jobs), unless a new timeout\n * is set before then. You may set a new timeout value for a job as many times\n * as desired. A timeout value of zero disables the timeout. Timers are\n * disposed of if the job is canceled or restarted.\n *\n * @param ms Optional: Number of milliseconds after which the job will be\n * canceled. Defaults to zero if not given.\n *\n * @param job Optional: the job to apply the timeout to. If none is given, the\n * active job is used.\n *\n * @returns the job to which the timeout was added or removed.\n *\n * @category Scheduling\n */\nexport function timeout<T>(ms: number, job?: Job<T>): Job<T>;\nexport function timeout(ms = 0, job: Job = getJob()) {\n let timer = timers.get(job);\n if (timer) {\n clearTimeout(timer);\n } else if (timer === undefined && !job.result()) {\n // no timeout has been set since job was last restarted,\n // so we need to arrange to clear it\n job.must(timeout.bind(null, 0, job));\n }\n if (job.result()) {\n // allow restarted timer to set a new must()\n timers.delete(job);\n } else if (ms) {\n timers.set(job, setTimeout(() => { timers.set(job, null); job.end(); }, ms));\n } else {\n timers.set(job, null); // Zero = cancel timeout, but don't duplicate must() if called again\n }\n return job;\n}\n\nconst abortSignals = new WeakMap<Job, AbortSignal>();\n\n/**\n * Get an AbortSignal that aborts when the job ends or is restarted.\n *\n * @param job Optional: the job to get an AbortSignal for. If none is given,\n * the active job is used.\n *\n * @returns the AbortSignal\n *\n * @category Jobs\n */\nexport function abortSignal(job: Job = getJob()) {\n let signal = abortSignals.get(job);\n if (!signal) {\n const ctrl = new AbortController;\n signal = ctrl.signal;\n job.must(() => { abortSignals.set(job, null); ctrl.abort(); });\n abortSignals.set(job, signal);\n if (job.result()) ctrl.abort();\n }\n return signal;\n}\n\n/**\n * Wrap a function in a {@link Job} that restarts each time the resulting\n * function is called, thereby canceling any nested jobs and cleaning up any\n * resources used by previous calls. (This can be useful for such things as\n * canceling an in-progress search when the user types more text in a field.)\n *\n * The restarting job will be ended when the job that invoked `restarting()`\n * is finished, canceled, or restarted. Calling the wrapped function after its\n * job has ended will result in an error. You can wrap any function any number\n * of times: each call to `restarting()` creates a new, distinct \"restarting\n * job\" and function wrapper to go with it.\n *\n * @param task (Optional) The function to be wrapped. This can be any function:\n * the returned wrapper function will match its call signature exactly, including\n * overloads. (So for example you could wrap the {@link start} API via\n * `restarting(start)`, to create a function you can pass job-start functions to.\n * When called, the function would cancel any outstanding job from a previous\n * call, and start the new one in its place.)\n *\n * @returns A function of identical type to the input function. If no input\n * function was given, the returned function will just take one argument (a\n * zero-argument function optionally returning a {@link CleanupFn}).\n *\n * @category Jobs\n */\nexport function restarting<F extends AnyFunction>(task: F): F\nexport function restarting(): (task: () => OptionalCleanup) => void\nexport function restarting<F extends AnyFunction>(task?: F): F {\n const outer = getJob(), inner = makeJob<never>(outer), {end} = inner;\n task ||= <F>((f: () => OptionalCleanup) => { inner.must(f()); });\n inner.asyncCatch(e => outer.asyncThrow(e));\n return <F>function(this: ThisParameterType<F>) {\n inner.restart().must(outer.release(end));\n const old = swapCtx(makeCtx(inner));\n try { return apply(task, this, arguments); }\n catch(e) { inner.restart(); throw e; }\n finally { freeCtx(swapCtx(old)); }\n };\n}\n\n/**\n * Wrap an argument-taking function so it will run in (and returns) a new Job\n * when called.\n *\n * This lets you avoid the common pattern of needing to write your functions or\n * methods like this:\n *\n * ```ts\n * function outer(arg1, arg2) {\n * return start(function*() {\n * // ...\n * })\n * }\n * ```\n * and instead write them like this:\n * ```ts\n * const outer = task(function *(arg1, arg2) {\n * // ...\n * });\n * ```\n * or this:\n * ```ts\n * class Something {\n * ⁣⁣@task // auto-detects TC39 or legacy decorators\n * *someMethod(arg1): Yielding<SomeResultType> {\n * // ...\n * }\n * }\n * ```\n *\n * Important: if the wrapped function or method has overloads, the resulting\n * function type will be based on the **last** overload, because TypeScript (at\n * least as of 5.x) is still not very good at dealing with higher order\n * generics, especially if overloads are involved.\n *\n * Also note that TypeScript doesn't allow decorators to change the calling\n * signature or return type of a method, so even though the above method will\n * return a {@link Job}, TypeScript will only see it as a {@link Yielding}.\n *\n * This is fine if all you're going to do is `yield *` it to wait for the\n * result, but if you need to use any job-specific methods on it, you'll have to\n * pass it through {@link start} to have TypeScript treat it as an actual job.\n * (Luckily, start() has a fast path to return the original job if it's passed a\n * job, so you won't actually create a new job by doing this.)\n *\n * @param fn The function to wrap. A function returning a generator or\n * promise-like object (i.e., a {@link StartObj}).\n *\n * @returns A wrapped version of the function that passes through its arguments\n * to the original function, while running it in a new job. (The wrapper also\n * returns the job.)\n *\n * @category Jobs\n */\nexport function task<T, A extends any[], C>(fn: (this: C, ...args: A) => StartObj<T>): (this: C, ...args: A) => Job<T>;\n\n/** @hidden TC39 Decorator protocol */\nexport function task<T, A extends any[], C>(\n fn: (this: C, ...args: A) => StartObj<T>, ctx: {kind: \"method\"}\n): (this: C, ...args: A) => Job<T>;\n\n/** @hidden Legacy Decorator protocol */\nexport function task<T, A extends any[], C, D extends {value?: (this:C, ...args: A) => StartObj<T>}>(\n clsOrProto: any, name: string|symbol, desc: D\n): D\n\nexport function task<T, A extends any[], C, D extends {value?: (this:C, ...args: A) => StartObj<T>}>(\n fn: (this: C, ...args: A) => StartObj<T>, _ctx?: any, desc?: D\n): D | ((this: C, ...args: A) => Job<T>) {\n if (desc) return {...desc, value: task(desc.value)};\n return function (this: C, ...args: A) {\n return start(() => apply(fn, this, args));\n }\n}\n","import { Job, Yielding } from \"./types.ts\";\nimport { start } from \"./jobutils.ts\";\nimport { isValue, isError, markHandled } from \"./results.ts\";\nimport { isFunction } from \"./utils.ts\";\nimport { connect, Source } from \"./streams.ts\";\n\nexport function callOrWait<T>(\n source: any, method: string, handler: (job: Job<T>, val: T) => void, noArgs: (f?: any) => Yielding<T> | void\n) {\n if (source && isFunction(source[method])) return source[method]() as Yielding<T>;\n if (isFunction(source)) return (\n source.length === 0 ? noArgs(source) : false\n ) || start<T>(job => {\n connect(source as Source<T>, v => handler(job, v)).do(r => {\n if (isValue(r)) job.throw(new Error(\"Stream ended\"));\n else if (isError(r)) job.throw(markHandled(r));\n });\n });\n mustBeSourceOrSignal();\n}\n\nexport function mustBeSourceOrSignal() { throw new TypeError(\"not a source or signal\"); }\n"],"names":[],"mappings":";;AAAO,SAAS,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE;AACtC,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACvB,CAAC;AACM,SAAS,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE;AACxC,EAAE,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC;AACnC,CAAC;AACM,SAAS,QAAQ,CAAC,OAAO,EAAE;AAClC,EAAE,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACpC,CAAC;AACM,SAAS,QAAQ,CAAC,OAAO,EAAE;AAClC,EAAE,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;AAC7C,CAAC;A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,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AACpC,OAAO,CAAC,CAAC;AACT,KAAK,CAAC,CAAC;AACP,EAAE,oBAAoB,EAAE,CAAC;AACzB,CAAC;AACM,SAAS,oBAAoB,GAAG;AACvC,EAAE,MAAM,IAAI,SAAS,CAAC,wBAAwB,CAAC,CAAC;AAChD;;;;"}
package/dist/mod.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { d as defer, i as isFunction } from './utils-P0JEpWXG.mjs';
2
- import { r as resolver, a as rejecter, b as resolve, I as IsStream, c as backpressure, m as must, s as start, g as getJob, n as noop, t as throttle, d as detached, i as isCancel, e as isUnhandled, f as markHandled, h as isError, j as connect, k as fulfillPromise, l as callOrWait, o as restarting, p as current, q as mustBeSourceOrSignal, u as isValue } from './call-or-wait-COAmx32w.mjs';
3
- export { z as CancelError, C as CancelResult, E as ErrorResult, V as ValueResult, K as abortSignal, F as compose, x as getResult, G as into, w as isHandled, H as isJobActive, B as makeJob, A as nativePromise, D as pipe, y as propagateResult, v as reject, L as task, J as timeout } from './call-or-wait-COAmx32w.mjs';
2
+ import { r as resolver, a as rejecter, b as resolve, I as IsStream, c as backpressure, m as must, s as start, g as getJob, n as noop, t as throttle, d as detached, i as isCancel, e as isUnhandled, f as markHandled, h as isError, j as connect, k as fulfillPromise, l as callOrWait, o as restarting, p as current, q as mustBeSourceOrSignal, u as isValue } from './call-or-wait-DpJBh_pS.mjs';
3
+ export { z as CancelError, C as CancelResult, E as ErrorResult, V as ValueResult, K as abortSignal, F as compose, x as getResult, G as into, w as isHandled, H as isJobActive, B as makeJob, A as nativePromise, D as pipe, y as propagateResult, v as reject, L as task, J as timeout } from './call-or-wait-DpJBh_pS.mjs';
4
4
 
5
5
  function* to(p) {
6
6
  return yield (res) => Promise.resolve(p).then(resolver(res), rejecter(res));
package/dist/mod.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.mjs","sources":["../src/async.ts","../src/sources.ts","../src/sinks.ts","../src/operators.ts"],"sourcesContent":["import { Request, Yielding } from \"./types.ts\";\nimport { rejecter, resolve, resolver } from \"./results.ts\"\n\n/**\n * Convert a (possible) promise to something you can `yield *to()` in a job\n *\n * Much like `await valueOrPromiseLike` in an async function, using `yield\n * *to(valueOrPromiseLike)` in a {@link Job}'s generator function will return\n * the value or the result of the promise/promise-like object.\n *\n * @category Scheduling\n */\nexport function *to<T>(p: Promise<T> | PromiseLike<T> | T): Yielding<T> {\n return yield (res: Request<T>) => Promise.resolve(p).then(resolver(res), rejecter(res));\n}\n\n/**\n * Pause the job for the specified time in ms, e.g. `yield *sleep(1000)` to wait\n * one second.\n *\n * @category Scheduling\n */\nexport function *sleep(ms: number): Yielding<void> {\n try {\n var id: ReturnType<typeof setTimeout>;\n yield r => {\n id = setTimeout(() => { id = undefined; resolve(r, void 0); }, ms);\n }\n } finally {\n if (id) clearTimeout(id);\n }\n}\n","import { defer } from \"./defer.ts\";\nimport { type Stream, IsStream, backpressure, Sink, Connection, Backpressure, throttle, Inlet, Source } from \"./streams.ts\";\nimport { getJob, detached } from \"./tracking.ts\";\nimport { must, start } from \"./jobutils.ts\";\nimport { DisposeFn } from \"./types.ts\";\nimport { isCancel, isError, isUnhandled, markHandled, noop } from \"./results.ts\";\n\n/**\n * A function that emits events, with a .source they're emitted from\n *\n * Created using {@link emitter}.\n *\n * @category Types and Interfaces\n */\nexport interface Emitter<T> {\n /** Call the emitter to emit events on its .source */\n (val: T): void;\n /** An event source that receives the events */\n source: Source<T>;\n /** Close all current subscribers' connections */\n end: () => void;\n /** Close all current subscribers' connections with an error */\n throw: (e: any) => void;\n};\n\n/**\n * Create an event source and a function to emit events on it\n *\n * (Note: you must specify the event type (e.g. `emitter<number>()`), since\n * there's nothing else to infer it from.)\n *\n * @returns A function that emits events, with a .source property they're\n * emitted on.\n *\n * @category Stream Producers\n */\nexport function emitter<T>(): Emitter<T> {\n const emit = mockSource<T>();\n emit.source = share(emit.source);\n return emit;\n}\n\n/**\n * A stream that immediately closes\n *\n * @category Stream Producers\n */\nexport function empty(): Source<never> {\n return (_, conn) => (conn?.return(), IsStream);\n}\n\n/**\n * Convert an async iterable to an event source\n *\n * Each time the resulting source is subscribed to, it will emit an event for\n * each item output by the iterator, then end the stream. Pause/resume is\n * supported.\n *\n * @category Stream Producers\n */\nexport function fromAsyncIterable<T>(iterable: AsyncIterable<T>): Source<T> {\n return (sink, conn=start(), inlet) => {\n const ready = backpressure(inlet);\n const iter = iterable[Symbol.asyncIterator]();\n if (iter.return) must(() => iter.return());\n return ready(next), IsStream;\n function next() {\n iter.next().then(({value, done}) => {\n if (done) conn.return(); else ready(() => {\n if (sink(value), ready()) next(); else ready(next);\n })\n }, e => conn.throw(e));\n }\n }\n}\n\n/**\n * Create an event source from an element, window, or other event target\n *\n * You can manually override the expected event type using a type parameter,\n * e.g. `fromDomEvent<CustomEvent>(someTarget, \"custom-event\")`.\n *\n * @param target an HTMLElement, Window, Document, or other EventTarget.\n * @param type the name of the event to add a listener for\n * @param options a boolean capture option, or an object of event listener\n * options\n * @returns a source that can be subscribed or piped, issuing events from the\n * target of the specified type.\n *\n * @category Stream Producers\n */\nexport function fromDomEvent<T extends HTMLElement, K extends keyof HTMLElementEventMap>(\n target: T, type: K, options?: boolean | AddEventListenerOptions\n): Source<HTMLElementEventMap[K]>;\nexport function fromDomEvent<T extends Window, K extends keyof WindowEventMap>(\n target: T, type: K, options?: boolean | AddEventListenerOptions\n): Source<WindowEventMap[K]>;\nexport function fromDomEvent<T extends Document, K extends keyof DocumentEventMap>(\n target: T, type: K, options?: boolean | AddEventListenerOptions\n): Source<DocumentEventMap[K]>;\nexport function fromDomEvent<T extends Event>(\n target: EventTarget, type: string, options?: boolean | AddEventListenerOptions\n): Source<T>\nexport function fromDomEvent<T extends EventTarget, K extends string>(\n target: T, type: K, options?: boolean | AddEventListenerOptions\n): Source<Event> {\n return (sink) => {\n function push(v: Event) { sink(v); }\n target.addEventListener(type, push, options);\n must(() => target.removeEventListener(type, push, options));\n return IsStream;\n }\n}\n\n/**\n * Convert an iterable to a synchronous event source\n *\n * Each time the resulting source is subscribed to, it will emit an event for\n * each item in the iterator, then close the connection. Pause/resume is\n * supported.\n *\n * @category Stream Producers\n */\nexport function fromIterable<T>(iterable: Iterable<T>): Source<T> {\n return (sink, conn=start(), inlet) => {\n const ready = backpressure(inlet);\n const iter = iterable[Symbol.iterator]();\n if (iter.return) must(() => iter.return());\n return ready(loop), IsStream;\n function loop() {\n try {\n for(;;) {\n const {value, done} = iter.next();\n if (done) return conn.return();\n if (sink(value), !ready()) return ready(loop);\n }\n } catch (e) {\n conn.throw(e);\n }\n }\n }\n}\n\n/**\n * Convert a Promise to an event source\n *\n * Each time the resulting source is subscribed to, it will emit an event for\n * the result of the promise, then close the connection. (Unless the promise is\n * rejected, in which case the connection throws and closes each time the source\n * is subscribed.) Non-native promises and non-promise values are converted\n * using Promise.resolve().\n *\n * @category Stream Producers\n */\nexport function fromPromise<T>(promise: Promise<T>|PromiseLike<T>|T): Source<T> {\n return (sink, conn) => {\n const job = getJob();\n Promise.resolve(promise).then(\n v => void (job.result() || (sink(v), conn?.return())),\n e => void (job.result() || conn?.throw(e))\n )\n return IsStream;\n }\n}\n\n/**\n * Create an event source from an arbitrary subscribe/unsubscribe function\n *\n * The supplied \"subscribe\" function will be passed a 1-argument callback and\n * must return an unsubscribe function. The callback should be called with\n * events of the appropriate type, and the unsubscribe function will be called\n * when the connection is closed.\n *\n * (Note: it's okay if the act of subscribing causes an immediate callback, as\n * the subscribe function will be called in a separate microtask.)\n *\n * @category Stream Producers\n */\nexport function fromSubscribe<T>(subscribe: (cb: (val: T) => void) => DisposeFn): Source<T> {\n return (sink) => {\n const f = getJob().must(() => sink = noop);\n return defer(() => f.must(subscribe(v => { sink(v); }))), IsStream;\n }\n}\n\n/**\n * Create a source that emits a single given value\n *\n * @category Stream Producers\n */\nexport function fromValue<T>(val: T): Source<T> {\n return (sink, conn) => {\n must(() => { sink = noop; conn = undefined; })\n return defer(() => { sink(val); conn?.return(); }), IsStream;\n }\n}\n\n/**\n * Create an event source that issues a number every `ms` milliseconds (starting\n * with 0 after the first interval passes).\n *\n * @category Stream Producers\n */\nexport function interval(ms: number): Source<number> {\n return (sink) => {\n let idx = 0, id = setInterval(() => sink(idx++), ms);\n return must(() => clearInterval(id)), IsStream;\n }\n}\n\n/**\n * Create a dynamic source that is created each time it's subscribed\n *\n * @param factory A function returning a source of the desired type. It will be\n * called whenever the lazy() stream is subscribed, and its result subscribed to.\n *\n * @returns A stream of the same type as the factory function returns\n *\n * @category Stream Producers\n */\nexport function lazy<T>(factory: () => Stream<T>): Source<T> {\n return (sink, conn, inlet) => factory()(sink, conn, inlet)\n}\n\n/**\n * An {@link Emitter} with a ready() method, that only supports a single active\n * subscriber. (Useful for testing stream operators and sinks.)\n *\n * Created using {@link mockSource}().\n *\n * @category Types and Interfaces\n */\nexport interface MockSource<T> extends Emitter<T> {\n ready: Backpressure\n}\n\n/**\n * Like {@link emitter}, but with a ready() backpressure method. It also only\n * supports a single active subscriber. (Useful for testing stream operators\n * and sinks.)\n *\n * @category Stream Producers\n */\nexport function mockSource<T>(): MockSource<T> {\n let write: Sink<T>, outlet: Connection, ready: Backpressure;\n const emit: MockSource<T> = (val: T) => { if (write) write(val); };\n emit.source = (sink, conn, inlet) => {\n write = sink; outlet = conn; ready = backpressure(inlet);\n must(() => write = outlet = ready = undefined);\n return IsStream;\n };\n emit.end = () => outlet?.return();\n emit.throw = (e: any) => outlet?.throw(e);\n emit.ready = (cb?: () => any) => ready(cb);\n return emit;\n}\n\n/**\n * A stream that never emits or closes\n *\n * @category Stream Producers\n */\nexport function never(): Source<never> {\n return () => IsStream;\n}\n\n/**\n * Wrap a source to allow multiple subscribers to the same underlying stream\n *\n * The input source will be susbcribed when the output has at least one\n * subscriber, and unsubscribed when the output has no subscribers. The input\n * will be paused when any subscriber pauses, and will only be resumed when all\n * subscribers are unpaused. All subscribers are closed or thrown if the input\n * source closes or throws.\n *\n * (Generally speaking, you should place the share call as late in your\n * pipelines as possible, if you use it at all. It adds some overhead that is\n * wasted if the stream doesn't have multiple subscribers, and may be redundant\n * if an upstream source is already shared. It's mainly useful if there is a\n * lot of mapping, filtering, or other complicated processing taking place\n * upstream of the share, and you know for a fact there will be enough\n * subscribers to make it a bottleneck. You should probably also consider\n * putting some {@link slack}() either upstream or downstream of the share, if\n * the upstream supports backpressure.)\n *\n * @category Stream Operators\n */\nexport function share<T>(source: Stream<T>): Source<T> {\n let uplink: Connection;\n const\n links = new Set<[sink: Sink<T>, conn: Connection]>,\n inlets = new Map<Inlet, number>(), // refcounts of incoming inlets\n t = throttle(), // the actual onReady queue\n multi: Inlet = {\n // A multi-connection inlet that requires all downstreams to be ready\n isOpen() { return !uplink?.result(); },\n isReady() {\n if (this.isOpen()) {\n for (const [i] of inlets) if (!i.isReady()) return (t.pause(), false);\n return true;\n }\n t.pause();\n return false;\n },\n onReady(cb, job) {\n if (this.isOpen()) {\n t.onReady(cb, job);\n for (const [i] of inlets) i.isReady() || i.onReady(produce, job);\n }\n return this;\n }\n }\n ;\n function produce() { multi.isReady() && t.resume(); }\n\n return (sink, conn=start(), inlet) => {\n const self: [Sink<T>, Connection] = [sink, conn];\n links.add(self);\n if (inlet) inlets.set(inlet, 1+(inlets.get(inlet) || 0));\n conn.must(() => {\n links.delete(self);\n if (inlet) {\n inlets.set(inlet, inlets.get(inlet)-1);\n if (!inlets.get(inlet)) inlets.delete(inlet);\n }\n if (!links.size) uplink?.end();\n else if (multi.isReady() && !t.isReady()) defer(produce);\n });\n if (links.size === 1) {\n uplink = detached.connect(source, v => {\n for(const [s, c] of links) try { s(v) } catch(e) { c.throw(e); };\n }, multi).do(r => {\n uplink = undefined;\n if (isCancel(r)) return;\n if (isUnhandled(r)) markHandled(r);\n for(const [_, c] of links) isError(r) ? c.throw(r.err) : c.return();\n })\n }\n return IsStream;\n }\n}\n","import { Job, RecalcSource, Request, Suspend, Yielding } from \"./types.ts\"\nimport { defer } from \"./defer.ts\";\nimport { Connection, Inlet, Sink, Stream, connect, pipe, throttle } from \"./streams.ts\";\nimport { resolve, isError, markHandled, fulfillPromise, rejecter, resolver } from \"./results.ts\";\nimport { restarting, start, must } from \"./jobutils.ts\";\nimport { isFunction } from \"./utils.ts\";\nimport { Signal, until } from \"./signals.ts\"; // the until is needed for documentation link\nimport { callOrWait, mustBeSourceOrSignal } from \"./call-or-wait.ts\";\nimport { current } from \"./ambient.ts\";\n\n/**\n * The result type returned from calls to {@link Each}.next()\n *\n * @category Types and Interfaces\n */\nexport type EachResult<T> = {\n /** The value provided by the source being iterated */\n item: T;\n\n /**\n * A suspend callback that must be `yield`-ed before the next call to the\n * iterator's .next() method. (That is, you must `yield next` it exactly once\n * per loop pass. See {@link each}() for more details.)\n */\n next: Suspend<void>;\n}\n\n/**\n * The iterable returned by `yield *` {@link each}()\n *\n * @category Types and Interfaces\n */\nexport type Each<T> = IterableIterator<EachResult<T>>\n\n/**\n * Asynchronously iterate over an event source\n *\n * Usage:\n *\n * ```ts\n * for (const {item: event, next} of yield *each(mouseMove)) {\n * console.log(event.clientX, event.clientY);\n * yield next; // required exactly once per iteration, even/w continue!\n * }\n * ```\n *\n * each(eventSource) yield-returns an iterator of `{item, next}` pairs. The\n * item is the data supplied by the event source, and `next` is a\n * {@link Suspend}\\<void\\> that advances the iterator to the next item. It\n * *must* be yielded exactly once per loop iteration. If you use `continue` to\n * shortcut the loop body, you must `yield next` *before* doing so.\n *\n * The for-loop will end if the source ends, errors, or is canceled. The source\n * is paused while the loop body is running, and resumed when the `yield next`\n * happens. If events arrive anyway (e.g. because the source doesn't support\n * pausing), they will be ignored unless you pipe the source through the\n * {@link slack}() operator to provide a buffer. If the for-loop is exited\n * early for any reason (or the iterator's `.return()` is called), the source is\n * unsubscribed and the iteration ended.\n *\n * @category Stream Consumers\n */\nexport function *each<T>(src: Stream<T>): Yielding<Each<T>> {\n let yielded = false, waiter: Request<void>;\n const result: IteratorYieldResult<EachResult<T>> = {value: {item: undefined as T, next}, done: false};\n const t = throttle(), conn = connect(src, v => {\n t.pause();\n if (!waiter || conn.result()) return;\n result.value.item = v;\n resolve(waiter, waiter = void 0);\n }, t).do(r => {\n // Prevent unhandled throws from here - it'll be seen by the next `yield\n // next`, or in the next microtask if `yield next` is already running.\n if (isError(r)) markHandled(r);\n if (waiter) { defer(next.bind(null, waiter)); waiter = undefined; }\n });\n\n // Wait for first value to arrive (and get put in result) before returning the iterator\n t.pause(); yield next;\n return {\n [Symbol.iterator]() { return this; },\n next() {\n if (!yielded) throw new Error(\"Must `yield next` in loop\");\n yielded = false;\n return result;\n },\n return() { conn.end(); return {value: undefined, done: true}; },\n }\n function next(r: Request<void>) {\n if (waiter) throw new Error(\"Multiple `yield next` in loop\");\n yielded = true;\n if (conn.result()) {\n result.value = undefined;\n (result as IteratorResult<any>).done = true;\n fulfillPromise(resolver(r), rejecter(r), conn.result())\n } else {\n waiter = r;\n t.resume();\n }\n }\n}\n\n/**\n * An object that can be waited on with `yield *until()`, by calling its\n * \"uneventful.until\" method. (This mostly exists to allow Signals to optimize\n * their until() implementation, but is also open for extensions.)\n *\n * @category Types and Interfaces\n */\nexport interface UntilMethod<T> {\n /** Return an async op to resume once a truthy value is available */\n \"uneventful.until\"(): Yielding<T>\n}\n\n/**\n * An object that can be waited on with `yield *next()`, by calling its\n * \"uneventful.next\" method. (This mostly exists to allow Signals to optimize\n * their next() implementation, but is also open for extensions.)\n *\n * @category Types and Interfaces\n */\nexport interface NextMethod<T> {\n /** Return an async op to resume with the \"next\" (i.e. not current) value produced */\n \"uneventful.next\"(): Yielding<T>\n};\n\n/**\n * Wait for and return the next value (or error) from a data source (when\n * processed with `yield *` within a {@link Job}).\n *\n * This differs from {@link until}() in that it waits for the *next* value\n * (truthy or not!), and it never resumes immediately for signals, but instead\n * waits for the signal to *change*. (Also, it does not support zero-argument\n * functions, unless you wrap them with {@link cached}() first.)\n *\n * @param source The source to wait on, which can be:\n * - An object with an `\"uneventful.next\"` method returning a {@link Yielding}\n * (in which case the result will be the the result of calling that method)\n * - A {@link Signal} or {@link Source} (in which case the job resumes on the\n * next value it produces)\n *\n * (Note: if the supplied source is a function with a non-zero `.length`, it is\n * assumed to be a {@link Source}.)\n *\n * @returns a Yieldable that when processed with `yield *` in a job, will return\n * the triggered event, or signal value. An error is thrown if event stream\n * throws or closes early, or the signal throws.\n *\n * @category Stream Consumers\n * @category Scheduling\n */\nexport function next<T>(source: NextMethod<T> | Stream<T>): Yielding<T> {\n return callOrWait<T>(source, \"uneventful.next\", waitAny, mustBeSourceOrSignal);\n}\n\nfunction waitAny<T>(job: Job<T>, v: T) { job.return(v); }\n\n/**\n * Run a {@link restarting}() callback for each value produced by a source.\n *\n * With each event that occurs, any previous callback run is cleaned up before\n * the new one begins. (And the last run is cleaned up when the connection or\n * job ends.)\n *\n * This function is almost the exact opposite of {@link each}(), in that the\n * stream is never paused (unless you do so manually via a throttle or inlet),\n * and if the \"loop body\" (callback job) is still running when a new value\n * arrives, forEach() restarts the job instead of dropping the value.\n *\n * @param src An event source (i.e. a {@link Source} or {@link Signal})\n * @param sink A callback that receives values from the source\n * @param inlet An optional throttle or inlet that will be used to pause the\n * source (if it's a signal or supports backpressure)\n * @returns a {@link Connection} that can be used to detect the stream\n * end/error, or ended to close it early.\n *\n * @category Stream Consumers\n */\nexport function forEach<T>(src: Stream<T>, sink: Sink<T>, inlet?: Inlet): Connection;\n/**\n * When called without a source, return a callback suitable for use w/{@link pipe}().\n * e.g.:\n *\n * ```ts\n * pipe(someSource, ..., forEach(v => { doSomething(v); }), optionalInlet));\n * ```\n *\n */\nexport function forEach<T>(sink: Sink<T>, inlet?: Inlet): (src: Stream<T>) => Connection;\nexport function forEach<T>(\n src: Stream<T>|Sink<T>, sink?: Sink<T>|Inlet, inlet?: Inlet\n): Connection | ((src: Stream<T>) => Connection) {\n if (isFunction(sink)) return start(j => {\n (src as Stream<T>)(restarting(sink as Sink<T>), j, inlet)\n });\n inlet = sink as Inlet; sink = src as Sink<T>;\n return (src: Stream<T>) => forEach(src, sink as Sink<T>, inlet);\n}\n\n/**\n * Arrange for the current signal or rule to recalculate on demand\n *\n * This lets you interop with systems that have a way to query a value and\n * subscribe to changes to it, but not directly produce a signal. (Such as\n * querying the DOM state and using a MutationObserver.)\n *\n * By calling this with a {@link Source} or {@link RecalcSource}, you arrange\n * for it to be subscribed, if and when the call occurs in a rule or a cached\n * function that's in use by a rule (directly or indirectly). When the source\n * emits a value, the signal machinery will invalidate the caching of the\n * function or rule, forcing a recalculation and subsequent rule reruns, if\n * applicable.\n *\n * Note: you should generally only call the 1-argument version of this function\n * with \"static\" sources - i.e. ones that won't change on every call. Otherwise,\n * you will end up creating new signals each time, subscribing and unsubscribing\n * on every call to recalcWhen().\n *\n * If the source needs to reference some object, it's best to use the 2-argument\n * version (i.e. `recalcWhen(someObj, factory)`, where `factory` is a function\n * that takes `someObj` and returns a suitable {@link RecalcSource}.)\n *\n * @remarks\n * recalcWhen is specifically designed so that using it does not pull in any\n * part of Uneventful's signals framework, in the event a program doesn't\n * already use it. This means you can use it in library code to provide signal\n * compatibility, without adding bundle bloat to code that doesn't use signals.\n *\n * @category Signals\n */\n\nexport function recalcWhen(src: RecalcSource): void;\n/**\n * Two-argument variant of recalcWhen\n *\n * In certain circumstances, you may wish to use recalcWhen with a source\n * related to some object. You could call recalcWhen with a closure, but that\n * would create and discard signals on every call. So this 2-argument version\n * lets you avoid that by allowing the use of an arbitrary object as a key,\n * along with a factory function to turn the key into a {@link RecalcSource}.\n *\n * @param key an object to be used as a key\n *\n * @param factory a function that will be called with the key to obtain a\n * {@link RecalcSource}. (Note that this factory function must also be a static\n * function, not a closure, or the same memory thrash issue will occur!)\n */\nexport function recalcWhen<T extends WeakKey>(key: T, factory: (key: T) => RecalcSource): void;\nexport function recalcWhen<T extends WeakKey>(fnOrKey: T | RecalcSource, fn?: (key: T) => RecalcSource) {\n current.cell?.recalcWhen<T>(fnOrKey as T, fn);\n}\n\n/**\n * Find out whether the active signal is being observed, or just queried.\n *\n * If the return value is true, the caller is running within a signal\n * calculation that is being observed by subscribers (such as a rule or stream\n * listener). If the return value is false, the caller is running within a\n * signal calculation that is *not* observed by any subscribers, and the signal\n * will be recalculated whenever it transitions from unobserved to observed.\n *\n * Returns `undefined` if the caller isn't running in a signal calculation.\n *\n * @remarks Note that calling this function within a signal calculation even\n * once adds a *permanent*, implicit dependency to that signal, on whether the\n * signal is being observed. (As does using any job APIs directly.)\n *\n * The assumption here is that if you're checking whether it's observed, it's\n * because you only want to do certain things *while* it's being observed, so\n * the signal needs to be recalculated when it *starts* being observed, so you\n * can do those things. (If you need to undo or clean up those things when the\n * signal is no-longer observed, you can register a cleanup callback via e.g.\n * {@link must}(), or wrap them in a sub-job with start, connect, etc.)\n *\n * @category Signals\n */\nexport function isObserved(): boolean | undefined {\n return current.cell?.isObserved();\n}\n","import { fromIterable } from \"./sources.ts\";\nimport { Connection, IsStream, Source, Sink, Stream, Transformer, backpressure, throttle } from \"./streams.ts\";\nimport { isValue, noop } from \"./results.ts\";\nimport { start } from \"./jobutils.ts\";\n\n/**\n * Output multiple streams' contents in order (from an array/iterable of stream\n * sources)\n *\n * Streams are concatenated in order -- note that this means they need to not be\n * infinite if any subsequent streams are to be processed! The output is closed\n * when all sources are finished or if any source throws (in which case the\n * error propagates to the subscriber).\n *\n * Note: this function is just shorthand for {@link concatAll}({@link fromIterable}(*sources*)).\n *\n * @category Stream Operators\n */\nexport function concat<T>(sources: Stream<T>[] | Iterable<Stream<T>>): Source<T> {\n return concatAll(fromIterable(sources))\n}\n\n/**\n * Flatten a source of sources by emitting their contents in series\n *\n * Streams are concatenated in order -- note that this means they need to not be\n * infinite if any subsequent streams are to be processed! The output is closed\n * when all sources are finished or if any source throws (in which case the\n * error propagates to the subscriber).\n *\n * If you want to switch to a new stream whenever a new source arrives from the\n * input stream, use {@link switchAll} instead.\n *\n * @category Stream Operators\n */\nexport function concatAll<T>(sources: Stream<Stream<T>>): Source<T> {\n return (sink, conn=start(), inlet) => {\n let inner: Connection;\n const inputs: Stream<T>[] = [], t = throttle();\n let outer = conn.connect(sources, s => {\n inputs.push(s); startNext(); t.pause();\n }, t).do(r => {\n outer = undefined\n inputs.length || inner || !isValue(r) || conn.return();\n });\n function startNext() {\n inner ||= conn.connect(inputs.shift(), sink, inlet).do(r => {\n inner = undefined;\n inputs.length ? startNext() : (outer ? t.resume() : !isValue(r) || conn.return());\n });\n }\n return IsStream;\n }\n}\n\n/**\n * Map each value of a stream to a substream, then concatenate the resulting\n * substreams\n *\n * (This is just shorthand for `compose(map(mapper), concatAll)`.)\n *\n * If you want to switch to a new stream whenever a new event arrives on the\n * input stream, use {@link switchMap} instead.\n *\n * @category Stream Operators\n */\nexport function concatMap<T,R>(mapper: (v: T, idx: number) => Stream<R>): Transformer<T,R> {\n return src => concatAll(map(mapper)(src))\n}\n\n\n/**\n * Create a subset of a stream, based on a filter function (like Array.filter)\n *\n * The filter function receives the current index (zero-based) as well as the\n * current value. If it returns truth, the value will be passed to the output,\n * otherwise it will be skipped.\n *\n * If the filter function is typed as a Typescript type guard (i.e. as returning\n * `v is SomeType`), then the resulting source will be typed as\n * Source<SomeType>.\n *\n * @category Stream Operators\n */\nexport function filter<T,R extends T>(filter: (v: T, idx: number) => v is R): Transformer<T,R>;\nexport function filter<T>(filter: (v: T, idx: number) => boolean): Transformer<T>;\nexport function filter<T>(filter: (v: T, idx: number) => boolean): Transformer<T> {\n return src => (sink, conn, inlet) => {\n let idx = 0; return src(v => filter(v, idx++) && sink(v), conn, inlet);\n }\n}\n\n/**\n * Replace each value in a stream using a function (like Array.map)\n *\n * The mapping function receives the current index (zero-based) as well as the\n * current value.\n *\n * @category Stream Operators\n */\nexport function map<T,R>(mapper: (v: T, idx: number) => R): Transformer<T,R> {\n return src => (sink, conn, inlet) => {\n let idx = 0; return src(v => sink(mapper(v, idx++)), conn, inlet);\n }\n}\n\n/**\n * Create an event source by merging an array or iterable of event sources.\n *\n * The resulting source issues events whenever any of the input sources do, and\n * closes once they all do (or throws if any of them do).\n *\n * @category Stream Operators\n */\nexport function merge<T>(sources: Stream<T>[] | Iterable<Stream<T>>): Source<T> {\n return mergeAll(fromIterable(sources));\n}\n\n/**\n * Create an event source by merging sources from a stream of event sources\n *\n * The resulting source issues events whenever any of the input sources do, and\n * closes once they all do (or throws if any of them do).\n *\n * @category Stream Operators\n */\nexport function mergeAll<T>(sources: Stream<Stream<T>>): Source<T> {\n return (sink, conn=start(), inlet) => {\n const uplinks: Set<Connection> = new Set;\n let outer = conn.connect(sources, (s) => {\n const c = conn.connect(s, sink, inlet).do(r => {\n uplinks.delete(c);\n uplinks.size || outer || !isValue(r) || conn.return();\n });\n uplinks.add(c);\n }).do(r => {\n outer = undefined;\n uplinks.size || !isValue(r) || conn.return();\n });\n return IsStream;\n }\n}\n\n/**\n * Create an event source by merging sources created by mapping events to sources\n *\n * The resulting source issues events whenever any of the input sources do, and\n * closes once they all do (or throws if any of them do).\n *\n * (Note: this is just shorthand for `compose(map(mapper), mergeAll)`.)\n *\n * @category Stream Operators\n */\nexport function mergeMap<T,R>(mapper: (v: T, idx: number) => Stream<R>): Transformer<T,R> {\n return src => mergeAll(map(mapper)(src));\n}\n\n/**\n * Skip the first N items from a source\n *\n * (Equivalent to {@link skipWhile}() with a function that checks the index is < n.)\n *\n * @category Stream Operators\n */\nexport function skip<T>(n: number): Transformer<T> {\n return skipWhile((_, i) => i<n);\n}\n\n/**\n * Skip items from a stream until another source produces a value.\n *\n * If the notifier closes without producing a value, the output will\n * be empty. If the notifier throws, so will the output.\n *\n * @category Stream Operators\n */\nexport function skipUntil<T>(notifier: Stream<any>): Transformer<T> {\n return src => (sink, conn=start(), inlet) => {\n let taking = false;\n const c = conn.connect(notifier, () => { taking = true; c.end(); });\n return src(v => taking && sink(v), conn, inlet);\n }\n}\n\n/**\n * Skip items from a stream until a given condition is false, then output all\n * remaining items. The condition function is not called again once it returns\n * false.\n *\n * @category Stream Operators\n */\nexport function skipWhile<T>(condition: (v: T, index: number) => boolean) : Transformer<T> {\n return src => (sink, conn, inlet) => {\n let idx = 0, met = false;\n return src(v => (met ||= !condition(v, idx++)) && sink(v), conn, inlet);\n };\n}\n\n/**\n * Add job control and buffering to a stream\n *\n * This lets you block events from a stream that can't be paused, or allow for\n * some slack for a source that can sometimes get ahead of its sink.\n *\n * @param size The number of items to buffer when the sink is busy (i.e., the\n * sink is running or the connection is paused). If positive, the most recent N\n * items are kept (a \"sliding\" buffer), and if negative, the oldest N item are\n * kept (a \"dropping\" buffer). If zero, no items are buffered, and items are\n * dropped if received while the sink is busy.\n *\n * @param dropped Optional: a callback that will receive items when they are\n * dropped. (Useful for testing, performance instrumentation, error logging,\n * etc.)\n *\n * @category Stream Operators\n */\nexport function slack<T>(size: number, dropped: Sink<T> = noop): Transformer<T> {\n const max = Math.abs(size);\n return src => (sink, conn=start(), inlet) => {\n const buffer: T[] = [], ready = backpressure(inlet);\n let paused = false, draining = false;\n const t = throttle();\n conn.connect(src, v => {\n buffer.push(v);\n if (!draining && ready()) return drain();\n while (buffer.length > max) { dropped((size < 0) ? buffer.pop() : buffer.shift()); }\n if (buffer.length === max) { t.pause(); paused = true; }\n if (buffer.length) ready(drain);\n }, t).do(r => {\n if (isValue(r)) conn.return();\n });\n\n function drain() {\n draining = true;\n try {\n while(buffer.length) {\n sink(buffer.shift());\n if (paused && ready()) {\n paused = false; t.resume();\n }\n if (buffer.length && !ready()) {\n return ready(drain);\n }\n }\n } finally {\n draining = false;\n }\n }\n return IsStream;\n }\n}\n\n/**\n * Flatten a source of sources by emitting their contents until a new one\n * arrives.\n *\n * As each source arrives from the input stream, its values are sent to the\n * output, closing the previous one (if any). The output is closed when both\n * the input stream and the most-recently-arrived stream are finished. Errors\n * propagate to the output if any stream throws.\n *\n * (If you want to send *all* the values of each stream to the output without\n * stopping, input stream, use {@link concatAll} or {@link mergeAll} instead.)\n *\n * @category Stream Operators\n */\nexport function switchAll<T>(sources: Stream<Stream<T>>): Source<T> {\n return (sink, conn=start(), inlet) => {\n let inner: Connection;\n let outer = conn.connect(sources, s => {\n inner?.end();\n inner = conn.connect(s, sink, inlet).do(r => {\n inner = undefined;\n outer || !isValue(r) || conn.return();\n });\n }).do(r => {\n outer = undefined;\n inner || !isValue(r) || conn.return();\n });\n return IsStream;\n }\n}\n\n/**\n * Map each value of a stream to a substream, then output the resulting\n * substreams until a new value arrives.\n *\n * (This is just shorthand for `compose(map(mapper),`{@link switchAll `switchAll)`}.)\n *\n * (If you want to send *all* the values of each stream to the output without\n * stopping, input stream, use {@link concatMap} or {@link mergeMap} instead.)\n *\n * @category Stream Operators\n */\nexport function switchMap<T,R>(mapper: (v: T, idx: number) => Stream<R>): Transformer<T,R> {\n return src => switchAll(map(mapper)(src))\n}\n\n/**\n * Take the first N items from a source\n *\n * (Equivalent to {@link takeWhile}() with a function that checks the index is < n.)\n *\n * @category Stream Operators\n */\nexport function take<T>(n: number): Transformer<T> {\n return takeWhile((_, i) => i<n);\n}\n\n/**\n * Take items from a source until another source produces a value.\n *\n * If the notifier closes without producing a value, this will output all\n * elements of the input. But if the notifier throws, so will the output.\n *\n * @category Stream Operators\n */\nexport function takeUntil<T>(notifier: Stream<any>): Transformer<T> {\n return src => (sink, conn=start(), inlet) => {\n conn.connect(notifier, () => conn.return());\n return src(sink, conn, inlet);\n }\n}\n\n/**\n * Take items from a stream until a given condition is false, then close the\n * output. The condition function is not called again after it returns false.\n *\n * If the condition function is typed as a Typescript type guard (i.e. as\n * returning `v is SomeType`), then the resulting source will be typed as\n * Source<SomeType>.\n *\n * @category Stream Operators\n */\nexport function takeWhile<T,R extends T>(condition: (v: T, idx: number) => v is R): Transformer<T,R>;\nexport function takeWhile<T>(condition: (v: T, idx: number) => boolean): Transformer<T>;\nexport function takeWhile<T>(condition: (v: T, index: number) => boolean) : Transformer<T> {\n return src => (sink, conn, inlet) => {\n let idx = 0;\n return src(v => condition(v, idx++) ? sink(v) : conn?.return(), conn, inlet);\n };\n}\n"],"names":[],"mappings":";;;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,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;AACnF,GAAG,CAAC;AACJ;;;;"}
1
+ {"version":3,"file":"mod.mjs","sources":["../src/async.ts","../src/sources.ts","../src/sinks.ts","../src/operators.ts"],"sourcesContent":["import { Request, Yielding } from \"./types.ts\";\nimport { rejecter, resolve, resolver } from \"./results.ts\"\n\n/**\n * Convert a (possible) promise to something you can `yield *to()` in a job\n *\n * Much like `await valueOrPromiseLike` in an async function, using `yield\n * *to(valueOrPromiseLike)` in a {@link Job}'s generator function will return\n * the value or the result of the promise/promise-like object.\n *\n * @category Scheduling\n */\nexport function *to<T>(p: Promise<T> | PromiseLike<T> | T): Yielding<T> {\n return yield (res: Request<T>) => Promise.resolve(p).then(resolver(res), rejecter(res));\n}\n\n/**\n * Pause the job for the specified time in ms, e.g. `yield *sleep(1000)` to wait\n * one second.\n *\n * @category Scheduling\n */\nexport function *sleep(ms: number): Yielding<void> {\n try {\n var id: ReturnType<typeof setTimeout>;\n yield r => {\n id = setTimeout(() => { id = undefined; resolve(r, void 0); }, ms);\n }\n } finally {\n if (id) clearTimeout(id);\n }\n}\n","import { defer } from \"./defer.ts\";\nimport { type Stream, IsStream, backpressure, Sink, Connection, Backpressure, throttle, Inlet, Source } from \"./streams.ts\";\nimport { getJob, detached } from \"./tracking.ts\";\nimport { must, start } from \"./jobutils.ts\";\nimport { DisposeFn } from \"./types.ts\";\nimport { isCancel, isError, isUnhandled, markHandled, noop } from \"./results.ts\";\n\n/**\n * A function that emits events, with a .source they're emitted from\n *\n * Created using {@link emitter}.\n *\n * @category Types and Interfaces\n */\nexport interface Emitter<T> {\n /** Call the emitter to emit events on its .source */\n (val: T): void;\n /** An event source that receives the events */\n source: Source<T>;\n /** Close all current subscribers' connections */\n end: () => void;\n /** Close all current subscribers' connections with an error */\n throw: (e: any) => void;\n};\n\n/**\n * Create an event source and a function to emit events on it\n *\n * (Note: you must specify the event type (e.g. `emitter<number>()`), since\n * there's nothing else to infer it from.)\n *\n * @returns A function that emits events, with a .source property they're\n * emitted on.\n *\n * @category Stream Producers\n */\nexport function emitter<T>(): Emitter<T> {\n const emit = mockSource<T>();\n emit.source = share(emit.source);\n return emit;\n}\n\n/**\n * A stream that immediately closes\n *\n * @category Stream Producers\n */\nexport function empty(): Source<never> {\n return (_, conn) => (conn?.return(), IsStream);\n}\n\n/**\n * Convert an async iterable to an event source\n *\n * Each time the resulting source is subscribed to, it will emit an event for\n * each item output by the iterator, then end the stream. Pause/resume is\n * supported.\n *\n * @category Stream Producers\n */\nexport function fromAsyncIterable<T>(iterable: AsyncIterable<T>): Source<T> {\n return (sink, conn=start(), inlet) => {\n const ready = backpressure(inlet);\n const iter = iterable[Symbol.asyncIterator]();\n if (iter.return) must(() => iter.return());\n return ready(next), IsStream;\n function next() {\n iter.next().then(({value, done}) => {\n if (done) conn.return(); else ready(() => {\n if (sink(value), ready()) next(); else ready(next);\n })\n }, e => conn.throw(e));\n }\n }\n}\n\n/**\n * Create an event source from an element, window, or other event target\n *\n * You can manually override the expected event type using a type parameter,\n * e.g. `fromDomEvent<CustomEvent>(someTarget, \"custom-event\")`.\n *\n * @param target an HTMLElement, Window, Document, or other EventTarget.\n * @param type the name of the event to add a listener for\n * @param options a boolean capture option, or an object of event listener\n * options\n * @returns a source that can be subscribed or piped, issuing events from the\n * target of the specified type.\n *\n * @category Stream Producers\n */\nexport function fromDomEvent<T extends HTMLElement, K extends keyof HTMLElementEventMap>(\n target: T, type: K, options?: boolean | AddEventListenerOptions\n): Source<HTMLElementEventMap[K]>;\nexport function fromDomEvent<T extends Window, K extends keyof WindowEventMap>(\n target: T, type: K, options?: boolean | AddEventListenerOptions\n): Source<WindowEventMap[K]>;\nexport function fromDomEvent<T extends Document, K extends keyof DocumentEventMap>(\n target: T, type: K, options?: boolean | AddEventListenerOptions\n): Source<DocumentEventMap[K]>;\nexport function fromDomEvent<T extends Event>(\n target: EventTarget, type: string, options?: boolean | AddEventListenerOptions\n): Source<T>\nexport function fromDomEvent<T extends EventTarget, K extends string>(\n target: T, type: K, options?: boolean | AddEventListenerOptions\n): Source<Event> {\n return (sink) => {\n function push(v: Event) { sink(v); }\n target.addEventListener(type, push, options);\n must(() => target.removeEventListener(type, push, options));\n return IsStream;\n }\n}\n\n/**\n * Convert an iterable to a synchronous event source\n *\n * Each time the resulting source is subscribed to, it will emit an event for\n * each item in the iterator, then close the connection. Pause/resume is\n * supported.\n *\n * @category Stream Producers\n */\nexport function fromIterable<T>(iterable: Iterable<T>): Source<T> {\n return (sink, conn=start(), inlet) => {\n const ready = backpressure(inlet);\n const iter = iterable[Symbol.iterator]();\n if (iter.return) must(() => iter.return());\n return ready(loop), IsStream;\n function loop() {\n try {\n for(;;) {\n const {value, done} = iter.next();\n if (done) return conn.return();\n if (sink(value), !ready()) return ready(loop);\n }\n } catch (e) {\n conn.throw(e);\n }\n }\n }\n}\n\n/**\n * Convert a Promise to an event source\n *\n * Each time the resulting source is subscribed to, it will emit an event for\n * the result of the promise, then close the connection. (Unless the promise is\n * rejected, in which case the connection throws and closes each time the source\n * is subscribed.) Non-native promises and non-promise values are converted\n * using Promise.resolve().\n *\n * @category Stream Producers\n */\nexport function fromPromise<T>(promise: Promise<T>|PromiseLike<T>|T): Source<T> {\n return (sink, conn) => {\n const job = getJob();\n Promise.resolve(promise).then(\n v => void (job.result() || (sink(v), conn?.return())),\n e => void (job.result() || conn?.throw(e))\n )\n return IsStream;\n }\n}\n\n/**\n * Create an event source from an arbitrary subscribe/unsubscribe function\n *\n * The supplied \"subscribe\" function will be passed a 1-argument callback and\n * must return an unsubscribe function. The callback should be called with\n * events of the appropriate type, and the unsubscribe function will be called\n * when the connection is closed.\n *\n * (Note: it's okay if the act of subscribing causes an immediate callback, as\n * the subscribe function will be called in a separate microtask.)\n *\n * @category Stream Producers\n */\nexport function fromSubscribe<T>(subscribe: (cb: (val: T) => void) => DisposeFn): Source<T> {\n return (sink) => {\n const f = getJob().must(() => sink = noop);\n return defer(() => f.must(subscribe(v => { sink(v); }))), IsStream;\n }\n}\n\n/**\n * Create a source that emits a single given value\n *\n * @category Stream Producers\n */\nexport function fromValue<T>(val: T): Source<T> {\n return (sink, conn) => {\n must(() => { sink = noop; conn = undefined; })\n return defer(() => { sink(val); conn?.return(); }), IsStream;\n }\n}\n\n/**\n * Create an event source that issues a number every `ms` milliseconds (starting\n * with 0 after the first interval passes).\n *\n * @category Stream Producers\n */\nexport function interval(ms: number): Source<number> {\n return (sink) => {\n let idx = 0, id = setInterval(() => sink(idx++), ms);\n return must(() => clearInterval(id)), IsStream;\n }\n}\n\n/**\n * Create a dynamic source that is created each time it's subscribed\n *\n * @param factory A function returning a source of the desired type. It will be\n * called whenever the lazy() stream is subscribed, and its result subscribed to.\n *\n * @returns A stream of the same type as the factory function returns\n *\n * @category Stream Producers\n */\nexport function lazy<T>(factory: () => Stream<T>): Source<T> {\n return (sink, conn, inlet) => factory()(sink, conn, inlet)\n}\n\n/**\n * An {@link Emitter} with a ready() method, that only supports a single active\n * subscriber. (Useful for testing stream operators and sinks.)\n *\n * Created using {@link mockSource}().\n *\n * @category Types and Interfaces\n */\nexport interface MockSource<T> extends Emitter<T> {\n ready: Backpressure\n}\n\n/**\n * Like {@link emitter}, but with a ready() backpressure method. It also only\n * supports a single active subscriber. (Useful for testing stream operators\n * and sinks.)\n *\n * @category Stream Producers\n */\nexport function mockSource<T>(): MockSource<T> {\n let write: Sink<T>, outlet: Connection, ready: Backpressure;\n const emit: MockSource<T> = (val: T) => { if (write) write(val); };\n emit.source = (sink, conn, inlet) => {\n write = sink; outlet = conn; ready = backpressure(inlet);\n must(() => write = outlet = ready = undefined);\n return IsStream;\n };\n emit.end = () => outlet?.return();\n emit.throw = (e: any) => outlet?.throw(e);\n emit.ready = (cb?: () => any) => ready(cb);\n return emit;\n}\n\n/**\n * A stream that never emits or closes\n *\n * @category Stream Producers\n */\nexport function never(): Source<never> {\n return () => IsStream;\n}\n\n/**\n * Wrap a source to allow multiple subscribers to the same underlying stream\n *\n * The input source will be susbcribed when the output has at least one\n * subscriber, and unsubscribed when the output has no subscribers. The input\n * will be paused when any subscriber pauses, and will only be resumed when all\n * subscribers are unpaused. All subscribers are closed or thrown if the input\n * source closes or throws.\n *\n * (Generally speaking, you should place the share call as late in your\n * pipelines as possible, if you use it at all. It adds some overhead that is\n * wasted if the stream doesn't have multiple subscribers, and may be redundant\n * if an upstream source is already shared. It's mainly useful if there is a\n * lot of mapping, filtering, or other complicated processing taking place\n * upstream of the share, and you know for a fact there will be enough\n * subscribers to make it a bottleneck. You should probably also consider\n * putting some {@link slack}() either upstream or downstream of the share, if\n * the upstream supports backpressure.)\n *\n * @category Stream Operators\n */\nexport function share<T>(source: Stream<T>): Source<T> {\n let uplink: Connection;\n const\n links = new Set<[sink: Sink<T>, conn: Connection]>,\n inlets = new Map<Inlet, number>(), // refcounts of incoming inlets\n t = throttle(), // the actual onReady queue\n multi: Inlet = {\n // A multi-connection inlet that requires all downstreams to be ready\n isOpen() { return !uplink?.result(); },\n isReady() {\n if (this.isOpen()) {\n for (const [i] of inlets) if (!i.isReady()) return (t.pause(), false);\n return true;\n }\n t.pause();\n return false;\n },\n onReady(cb, job) {\n if (this.isOpen()) {\n t.onReady(cb, job);\n for (const [i] of inlets) i.isReady() || i.onReady(produce, job);\n }\n return this;\n }\n }\n ;\n function produce() { multi.isReady() && t.resume(); }\n\n return (sink, conn=start(), inlet) => {\n const self: [Sink<T>, Connection] = [sink, conn];\n links.add(self);\n if (inlet) inlets.set(inlet, 1+(inlets.get(inlet) || 0));\n conn.must(() => {\n links.delete(self);\n if (inlet) {\n inlets.set(inlet, inlets.get(inlet)-1);\n if (!inlets.get(inlet)) inlets.delete(inlet);\n }\n if (!links.size) uplink?.end();\n else if (multi.isReady() && !t.isReady()) defer(produce);\n });\n if (links.size === 1) {\n uplink = detached.connect(source, v => {\n for(const [s, c] of links) try { s(v) } catch(e) { c.throw(e); };\n }, multi).do(r => {\n uplink = undefined;\n if (isCancel(r)) return;\n if (isUnhandled(r)) markHandled(r);\n for(const [_, c] of links) isError(r) ? c.throw(r.err) : c.return();\n })\n }\n return IsStream;\n }\n}\n","import { Job, RecalcSource, Request, Suspend, Yielding } from \"./types.ts\"\nimport { defer } from \"./defer.ts\";\nimport { Connection, Inlet, Sink, Stream, connect, pipe, throttle } from \"./streams.ts\";\nimport { resolve, isError, markHandled, fulfillPromise, rejecter, resolver } from \"./results.ts\";\nimport { restarting, start, must } from \"./jobutils.ts\";\nimport { isFunction } from \"./utils.ts\";\nimport { Signal, until, cached } from \"./signals.ts\"; // the until and cached are needed for documentation links\nimport { callOrWait, mustBeSourceOrSignal } from \"./call-or-wait.ts\";\nimport { current } from \"./ambient.ts\";\n\n/**\n * The result type returned from calls to {@link Each}.next()\n *\n * @category Types and Interfaces\n */\nexport type EachResult<T> = {\n /** The value provided by the source being iterated */\n item: T;\n\n /**\n * A suspend callback that must be `yield`-ed before the next call to the\n * iterator's .next() method. (That is, you must `yield next` it exactly once\n * per loop pass. See {@link each}() for more details.)\n */\n next: Suspend<void>;\n}\n\n/**\n * The iterable returned by `yield *` {@link each}()\n *\n * @category Types and Interfaces\n */\nexport type Each<T> = IterableIterator<EachResult<T>>\n\n/**\n * Asynchronously iterate over an event source\n *\n * Usage:\n *\n * ```ts\n * for (const {item: event, next} of yield *each(mouseMove)) {\n * console.log(event.clientX, event.clientY);\n * yield next; // required exactly once per iteration, even/w continue!\n * }\n * ```\n *\n * each(eventSource) yield-returns an iterator of `{item, next}` pairs. The\n * item is the data supplied by the event source, and `next` is a\n * {@link Suspend}\\<void\\> that advances the iterator to the next item. It\n * *must* be yielded exactly once per loop iteration. If you use `continue` to\n * shortcut the loop body, you must `yield next` *before* doing so.\n *\n * The for-loop will end if the source ends, errors, or is canceled. The source\n * is paused while the loop body is running, and resumed when the `yield next`\n * happens. If events arrive anyway (e.g. because the source doesn't support\n * pausing), they will be ignored unless you pipe the source through the\n * {@link slack}() operator to provide a buffer. If the for-loop is exited\n * early for any reason (or the iterator's `.return()` is called), the source is\n * unsubscribed and the iteration ended.\n *\n * @category Stream Consumers\n */\nexport function *each<T>(src: Stream<T>): Yielding<Each<T>> {\n let yielded = false, waiter: Request<void>;\n const result: IteratorYieldResult<EachResult<T>> = {value: {item: undefined as T, next}, done: false};\n const t = throttle(), conn = connect(src, v => {\n t.pause();\n if (!waiter || conn.result()) return;\n result.value.item = v;\n resolve(waiter, waiter = void 0);\n }, t).do(r => {\n // Prevent unhandled throws from here - it'll be seen by the next `yield\n // next`, or in the next microtask if `yield next` is already running.\n if (isError(r)) markHandled(r);\n if (waiter) { defer(next.bind(null, waiter)); waiter = undefined; }\n });\n\n // Wait for first value to arrive (and get put in result) before returning the iterator\n t.pause(); yield next;\n return {\n [Symbol.iterator]() { return this; },\n next() {\n if (!yielded) throw new Error(\"Must `yield next` in loop\");\n yielded = false;\n return result;\n },\n return() { conn.end(); return {value: undefined, done: true}; },\n }\n function next(r: Request<void>) {\n if (waiter) throw new Error(\"Multiple `yield next` in loop\");\n yielded = true;\n if (conn.result()) {\n result.value = undefined;\n (result as IteratorResult<any>).done = true;\n fulfillPromise(resolver(r), rejecter(r), conn.result())\n } else {\n waiter = r;\n t.resume();\n }\n }\n}\n\n/**\n * An object that can be waited on with `yield *until()`, by calling its\n * \"uneventful.until\" method. (This mostly exists to allow Signals to optimize\n * their until() implementation, but is also open for extensions.)\n *\n * @category Types and Interfaces\n */\nexport interface UntilMethod<T> {\n /** Return an async op to resume once a truthy value is available */\n \"uneventful.until\"(): Yielding<T>\n}\n\n/**\n * An object that can be waited on with `yield *next()`, by calling its\n * \"uneventful.next\" method. (This mostly exists to allow Signals to optimize\n * their next() implementation, but is also open for extensions.)\n *\n * @category Types and Interfaces\n */\nexport interface NextMethod<T> {\n /** Return an async op to resume with the \"next\" (i.e. not current) value produced */\n \"uneventful.next\"(): Yielding<T>\n};\n\n/**\n * Wait for and return the next value (or error) from a data source (when\n * processed with `yield *` within a {@link Job}).\n *\n * This differs from {@link until}() in that it waits for the *next* value\n * (truthy or not!), and it never resumes immediately for signals, but instead\n * waits for the signal to *change*. (Also, it does not support zero-argument\n * functions, unless you wrap them with {@link cached}() first.)\n *\n * @param source The source to wait on, which can be:\n * - An object with an `\"uneventful.next\"` method returning a {@link Yielding}\n * (in which case the result will be the the result of calling that method)\n * - A {@link Signal} or {@link Source} (in which case the job resumes on the\n * next value it produces)\n *\n * (Note: if the supplied source is a function with a non-zero `.length`, it is\n * assumed to be a {@link Source}.)\n *\n * @returns a Yieldable that when processed with `yield *` in a job, will return\n * the triggered event, or signal value. An error is thrown if event stream\n * throws or closes early, or the signal throws.\n *\n * @category Stream Consumers\n * @category Scheduling\n */\nexport function next<T>(source: NextMethod<T> | Stream<T>): Yielding<T> {\n return callOrWait<T>(source, \"uneventful.next\", waitAny, mustBeSourceOrSignal);\n}\n\nfunction waitAny<T>(job: Job<T>, v: T) { job.return(v); }\n\n/**\n * Run a {@link restarting}() callback for each value produced by a source.\n *\n * With each event that occurs, any previous callback run is cleaned up before\n * the new one begins. (And the last run is cleaned up when the connection or\n * job ends.)\n *\n * This function is almost the exact opposite of {@link each}(), in that the\n * stream is never paused (unless you do so manually via a throttle or inlet),\n * and if the \"loop body\" (callback job) is still running when a new value\n * arrives, forEach() restarts the job instead of dropping the value.\n *\n * @param src An event source (i.e. a {@link Source} or {@link Signal})\n * @param sink A callback that receives values from the source\n * @param inlet An optional throttle or inlet that will be used to pause the\n * source (if it's a signal or supports backpressure)\n * @returns a {@link Connection} that can be used to detect the stream\n * end/error, or ended to close it early.\n *\n * @category Stream Consumers\n */\nexport function forEach<T>(src: Stream<T>, sink: Sink<T>, inlet?: Inlet): Connection;\n/**\n * When called without a source, return a callback suitable for use w/{@link pipe}().\n * e.g.:\n *\n * ```ts\n * pipe(someSource, ..., forEach(v => { doSomething(v); }), optionalInlet));\n * ```\n *\n */\nexport function forEach<T>(sink: Sink<T>, inlet?: Inlet): (src: Stream<T>) => Connection;\nexport function forEach<T>(\n src: Stream<T>|Sink<T>, sink?: Sink<T>|Inlet, inlet?: Inlet\n): Connection | ((src: Stream<T>) => Connection) {\n if (isFunction(sink)) return start(j => {\n (src as Stream<T>)(restarting(sink as Sink<T>), j, inlet)\n });\n inlet = sink as Inlet; sink = src as Sink<T>;\n return (src: Stream<T>) => forEach(src, sink as Sink<T>, inlet);\n}\n\n/**\n * Arrange for the current signal or rule to recalculate on demand\n *\n * This lets you interop with systems that have a way to query a value and\n * subscribe to changes to it, but not directly produce a signal. (Such as\n * querying the DOM state and using a MutationObserver.)\n *\n * By calling this with a {@link Source} or {@link RecalcSource}, you arrange\n * for it to be subscribed, if and when the call occurs in a rule or a cached\n * function that's in use by a rule (directly or indirectly). When the source\n * emits a value, the signal machinery will invalidate the caching of the\n * function or rule, forcing a recalculation and subsequent rule reruns, if\n * applicable.\n *\n * Note: you should generally only call the 1-argument version of this function\n * with \"static\" sources - i.e. ones that won't change on every call. Otherwise,\n * you will end up creating new signals each time, subscribing and unsubscribing\n * on every call to recalcWhen().\n *\n * If the source needs to reference some object, it's best to use the 2-argument\n * version (i.e. `recalcWhen(someObj, factory)`, where `factory` is a function\n * that takes `someObj` and returns a suitable {@link RecalcSource}.)\n *\n * @remarks\n * recalcWhen is specifically designed so that using it does not pull in any\n * part of Uneventful's signals framework, in the event a program doesn't\n * already use it. This means you can use it in library code to provide signal\n * compatibility, without adding bundle bloat to code that doesn't use signals.\n *\n * @category Signals\n */\n\nexport function recalcWhen(src: RecalcSource): void;\n/**\n * Two-argument variant of recalcWhen\n *\n * In certain circumstances, you may wish to use recalcWhen with a source\n * related to some object. You could call recalcWhen with a closure, but that\n * would create and discard signals on every call. So this 2-argument version\n * lets you avoid that by allowing the use of an arbitrary object as a key,\n * along with a factory function to turn the key into a {@link RecalcSource}.\n *\n * @param key an object to be used as a key\n *\n * @param factory a function that will be called with the key to obtain a\n * {@link RecalcSource}. (Note that this factory function must also be a static\n * function, not a closure, or the same memory thrash issue will occur!)\n */\nexport function recalcWhen<T extends WeakKey>(key: T, factory: (key: T) => RecalcSource): void;\nexport function recalcWhen<T extends WeakKey>(fnOrKey: T | RecalcSource, fn?: (key: T) => RecalcSource) {\n current.cell?.recalcWhen<T>(fnOrKey as T, fn);\n}\n\n/**\n * Find out whether the active signal is being observed, or just queried.\n *\n * If the return value is true, the caller is running within a signal\n * calculation that is being observed by subscribers (such as a rule or stream\n * listener). If the return value is false, the caller is running within a\n * signal calculation that is *not* observed by any subscribers, and the signal\n * will be recalculated whenever it transitions from unobserved to observed.\n *\n * Returns `undefined` if the caller isn't running in a signal calculation.\n *\n * @remarks Note that calling this function within a signal calculation even\n * once adds a *permanent*, implicit dependency to that signal, on whether the\n * signal is being observed. (As does using any job APIs directly.)\n *\n * The assumption here is that if you're checking whether it's observed, it's\n * because you only want to do certain things *while* it's being observed, so\n * the signal needs to be recalculated when it *starts* being observed, so you\n * can do those things. (If you need to undo or clean up those things when the\n * signal is no-longer observed, you can register a cleanup callback via e.g.\n * {@link must}(), or wrap them in a sub-job with start, connect, etc.)\n *\n * @category Signals\n */\nexport function isObserved(): boolean | undefined {\n return current.cell?.isObserved();\n}\n","import { fromIterable } from \"./sources.ts\";\nimport { Connection, IsStream, Source, Sink, Stream, Transformer, backpressure, throttle } from \"./streams.ts\";\nimport { isValue, noop } from \"./results.ts\";\nimport { start } from \"./jobutils.ts\";\n\n/**\n * Output multiple streams' contents in order (from an array/iterable of stream\n * sources)\n *\n * Streams are concatenated in order -- note that this means they need to not be\n * infinite if any subsequent streams are to be processed! The output is closed\n * when all sources are finished or if any source throws (in which case the\n * error propagates to the subscriber).\n *\n * Note: this function is just shorthand for {@link concatAll}({@link fromIterable}(*sources*)).\n *\n * @category Stream Operators\n */\nexport function concat<T>(sources: Stream<T>[] | Iterable<Stream<T>>): Source<T> {\n return concatAll(fromIterable(sources))\n}\n\n/**\n * Flatten a source of sources by emitting their contents in series\n *\n * Streams are concatenated in order -- note that this means they need to not be\n * infinite if any subsequent streams are to be processed! The output is closed\n * when all sources are finished or if any source throws (in which case the\n * error propagates to the subscriber).\n *\n * If you want to switch to a new stream whenever a new source arrives from the\n * input stream, use {@link switchAll} instead.\n *\n * @category Stream Operators\n */\nexport function concatAll<T>(sources: Stream<Stream<T>>): Source<T> {\n return (sink, conn=start(), inlet) => {\n let inner: Connection;\n const inputs: Stream<T>[] = [], t = throttle();\n let outer = conn.connect(sources, s => {\n inputs.push(s); startNext(); t.pause();\n }, t).do(r => {\n outer = undefined\n inputs.length || inner || !isValue(r) || conn.return();\n });\n function startNext() {\n inner ||= conn.connect(inputs.shift(), sink, inlet).do(r => {\n inner = undefined;\n inputs.length ? startNext() : (outer ? t.resume() : !isValue(r) || conn.return());\n });\n }\n return IsStream;\n }\n}\n\n/**\n * Map each value of a stream to a substream, then concatenate the resulting\n * substreams\n *\n * (This is just shorthand for `compose(map(mapper), concatAll)`.)\n *\n * If you want to switch to a new stream whenever a new event arrives on the\n * input stream, use {@link switchMap} instead.\n *\n * @category Stream Operators\n */\nexport function concatMap<T,R>(mapper: (v: T, idx: number) => Stream<R>): Transformer<T,R> {\n return src => concatAll(map(mapper)(src))\n}\n\n\n/**\n * Create a subset of a stream, based on a filter function (like Array.filter)\n *\n * The filter function receives the current index (zero-based) as well as the\n * current value. If it returns truth, the value will be passed to the output,\n * otherwise it will be skipped.\n *\n * If the filter function is typed as a Typescript type guard (i.e. as returning\n * `v is SomeType`), then the resulting source will be typed as\n * Source<SomeType>.\n *\n * @category Stream Operators\n */\nexport function filter<T,R extends T>(filter: (v: T, idx: number) => v is R): Transformer<T,R>;\nexport function filter<T>(filter: (v: T, idx: number) => boolean): Transformer<T>;\nexport function filter<T>(filter: (v: T, idx: number) => boolean): Transformer<T> {\n return src => (sink, conn, inlet) => {\n let idx = 0; return src(v => filter(v, idx++) && sink(v), conn, inlet);\n }\n}\n\n/**\n * Replace each value in a stream using a function (like Array.map)\n *\n * The mapping function receives the current index (zero-based) as well as the\n * current value.\n *\n * @category Stream Operators\n */\nexport function map<T,R>(mapper: (v: T, idx: number) => R): Transformer<T,R> {\n return src => (sink, conn, inlet) => {\n let idx = 0; return src(v => sink(mapper(v, idx++)), conn, inlet);\n }\n}\n\n/**\n * Create an event source by merging an array or iterable of event sources.\n *\n * The resulting source issues events whenever any of the input sources do, and\n * closes once they all do (or throws if any of them do).\n *\n * @category Stream Operators\n */\nexport function merge<T>(sources: Stream<T>[] | Iterable<Stream<T>>): Source<T> {\n return mergeAll(fromIterable(sources));\n}\n\n/**\n * Create an event source by merging sources from a stream of event sources\n *\n * The resulting source issues events whenever any of the input sources do, and\n * closes once they all do (or throws if any of them do).\n *\n * @category Stream Operators\n */\nexport function mergeAll<T>(sources: Stream<Stream<T>>): Source<T> {\n return (sink, conn=start(), inlet) => {\n const uplinks: Set<Connection> = new Set;\n let outer = conn.connect(sources, (s) => {\n const c = conn.connect(s, sink, inlet).do(r => {\n uplinks.delete(c);\n uplinks.size || outer || !isValue(r) || conn.return();\n });\n uplinks.add(c);\n }).do(r => {\n outer = undefined;\n uplinks.size || !isValue(r) || conn.return();\n });\n return IsStream;\n }\n}\n\n/**\n * Create an event source by merging sources created by mapping events to sources\n *\n * The resulting source issues events whenever any of the input sources do, and\n * closes once they all do (or throws if any of them do).\n *\n * (Note: this is just shorthand for `compose(map(mapper), mergeAll)`.)\n *\n * @category Stream Operators\n */\nexport function mergeMap<T,R>(mapper: (v: T, idx: number) => Stream<R>): Transformer<T,R> {\n return src => mergeAll(map(mapper)(src));\n}\n\n/**\n * Skip the first N items from a source\n *\n * (Equivalent to {@link skipWhile}() with a function that checks the index is < n.)\n *\n * @category Stream Operators\n */\nexport function skip<T>(n: number): Transformer<T> {\n return skipWhile((_, i) => i<n);\n}\n\n/**\n * Skip items from a stream until another source produces a value.\n *\n * If the notifier closes without producing a value, the output will\n * be empty. If the notifier throws, so will the output.\n *\n * @category Stream Operators\n */\nexport function skipUntil<T>(notifier: Stream<any>): Transformer<T> {\n return src => (sink, conn=start(), inlet) => {\n let taking = false;\n const c = conn.connect(notifier, () => { taking = true; c.end(); });\n return src(v => taking && sink(v), conn, inlet);\n }\n}\n\n/**\n * Skip items from a stream until a given condition is false, then output all\n * remaining items. The condition function is not called again once it returns\n * false.\n *\n * @category Stream Operators\n */\nexport function skipWhile<T>(condition: (v: T, index: number) => boolean) : Transformer<T> {\n return src => (sink, conn, inlet) => {\n let idx = 0, met = false;\n return src(v => (met ||= !condition(v, idx++)) && sink(v), conn, inlet);\n };\n}\n\n/**\n * Add job control and buffering to a stream\n *\n * This lets you block events from a stream that can't be paused, or allow for\n * some slack for a source that can sometimes get ahead of its sink.\n *\n * @param size The number of items to buffer when the sink is busy (i.e., the\n * sink is running or the connection is paused). If positive, the most recent N\n * items are kept (a \"sliding\" buffer), and if negative, the oldest N item are\n * kept (a \"dropping\" buffer). If zero, no items are buffered, and items are\n * dropped if received while the sink is busy.\n *\n * @param dropped Optional: a callback that will receive items when they are\n * dropped. (Useful for testing, performance instrumentation, error logging,\n * etc.)\n *\n * @category Stream Operators\n */\nexport function slack<T>(size: number, dropped: Sink<T> = noop): Transformer<T> {\n const max = Math.abs(size);\n return src => (sink, conn=start(), inlet) => {\n const buffer: T[] = [], ready = backpressure(inlet);\n let paused = false, draining = false;\n const t = throttle();\n conn.connect(src, v => {\n buffer.push(v);\n if (!draining && ready()) return drain();\n while (buffer.length > max) { dropped((size < 0) ? buffer.pop() : buffer.shift()); }\n if (buffer.length === max) { t.pause(); paused = true; }\n if (buffer.length) ready(drain);\n }, t).do(r => {\n if (isValue(r)) conn.return();\n });\n\n function drain() {\n draining = true;\n try {\n while(buffer.length) {\n sink(buffer.shift());\n if (paused && ready()) {\n paused = false; t.resume();\n }\n if (buffer.length && !ready()) {\n return ready(drain);\n }\n }\n } finally {\n draining = false;\n }\n }\n return IsStream;\n }\n}\n\n/**\n * Flatten a source of sources by emitting their contents until a new one\n * arrives.\n *\n * As each source arrives from the input stream, its values are sent to the\n * output, closing the previous one (if any). The output is closed when both\n * the input stream and the most-recently-arrived stream are finished. Errors\n * propagate to the output if any stream throws.\n *\n * (If you want to send *all* the values of each stream to the output without\n * stopping, input stream, use {@link concatAll} or {@link mergeAll} instead.)\n *\n * @category Stream Operators\n */\nexport function switchAll<T>(sources: Stream<Stream<T>>): Source<T> {\n return (sink, conn=start(), inlet) => {\n let inner: Connection;\n let outer = conn.connect(sources, s => {\n inner?.end();\n inner = conn.connect(s, sink, inlet).do(r => {\n inner = undefined;\n outer || !isValue(r) || conn.return();\n });\n }).do(r => {\n outer = undefined;\n inner || !isValue(r) || conn.return();\n });\n return IsStream;\n }\n}\n\n/**\n * Map each value of a stream to a substream, then output the resulting\n * substreams until a new value arrives.\n *\n * (This is just shorthand for `compose(map(mapper),`{@link switchAll `switchAll)`}.)\n *\n * (If you want to send *all* the values of each stream to the output without\n * stopping, input stream, use {@link concatMap} or {@link mergeMap} instead.)\n *\n * @category Stream Operators\n */\nexport function switchMap<T,R>(mapper: (v: T, idx: number) => Stream<R>): Transformer<T,R> {\n return src => switchAll(map(mapper)(src))\n}\n\n/**\n * Take the first N items from a source\n *\n * (Equivalent to {@link takeWhile}() with a function that checks the index is < n.)\n *\n * @category Stream Operators\n */\nexport function take<T>(n: number): Transformer<T> {\n return takeWhile((_, i) => i<n);\n}\n\n/**\n * Take items from a source until another source produces a value.\n *\n * If the notifier closes without producing a value, this will output all\n * elements of the input. But if the notifier throws, so will the output.\n *\n * @category Stream Operators\n */\nexport function takeUntil<T>(notifier: Stream<any>): Transformer<T> {\n return src => (sink, conn=start(), inlet) => {\n conn.connect(notifier, () => conn.return());\n return src(sink, conn, inlet);\n }\n}\n\n/**\n * Take items from a stream until a given condition is false, then close the\n * output. The condition function is not called again after it returns false.\n *\n * If the condition function is typed as a Typescript type guard (i.e. as\n * returning `v is SomeType`), then the resulting source will be typed as\n * Source<SomeType>.\n *\n * @category Stream Operators\n */\nexport function takeWhile<T,R extends T>(condition: (v: T, idx: number) => v is R): Transformer<T,R>;\nexport function takeWhile<T>(condition: (v: T, idx: number) => boolean): Transformer<T>;\nexport function takeWhile<T>(condition: (v: T, index: number) => boolean) : Transformer<T> {\n return src => (sink, conn, inlet) => {\n let idx = 0;\n return src(v => condition(v, idx++) ? sink(v) : conn?.return(), conn, inlet);\n };\n}\n"],"names":[],"mappings":";;;;AACO,UAAU,EAAE,CAAC,CAAC,EAAE;AACvB,EAAE,OAAO,MAAM,CAAC,GAAG,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;AAC9E,CAAC;AACM,UAAU,KAAK,CAAC,EAAE,EAAE;AAC3B,EAAE,IAAI;AACN,IAAI,IAAI,EAAE,CAAC;AACX,IAAI,MAAM,CAAC,CAAC,KAAK;AACjB,MAAM,EAAE,GAAG,UAAU,CAAC,MAAM;AAC5B,QAAQ,EAAE,GAAG,KAAK,CAAC,CAAC;AACpB,QAAQ,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;AAC3B,OAAO,EAAE,EAAE,CAAC,CAAC;AACb,KAAK,CAAC;AACN,GAAG,SAAS;AACZ,IAAI,IAAI,EAAE;AACV,MAAM,YAAY,CAAC,EAAE,CAAC,CAAC;AACvB,GAAG;AACH;;ACXO,SAAS,OAAO,GAAG;AAC1B,EAAE,MAAM,IAAI,GAAG,UAAU,EAAE,CAAC;AAC5B,EAAE,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACnC,EAAE,OAAO,IAAI,CAAC;AACd,CAAC;AACM,SAAS,KAAK,GAAG;AACxB,EAAE,OAAO,CAAC,CAAC,EAAE,IAAI,MAAM,IAAI,EAAE,MAAM,EAAE,EAAE,QAAQ,CAAC,CAAC;AACjD,CAAC;AACM,SAAS,iBAAiB,CAAC,QAAQ,EAAE;AAC5C,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,GA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O,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,KAAK;AACzC,IAAI,IAAI,GAAG,GAAG,CAAC,CAAC;AAChB,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;AACnF,GAAG,CAAC;AACJ;;;;"}
package/dist/signals.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { M as swapCtx, N as nullCtx, c as backpressure, I as IsStream, p as current, O as makeCtx, B as makeJob, h as isError, f as markHandled, d as detached, g as getJob, v as reject, b as resolve, P as freeCtx, l as callOrWait } from './call-or-wait-COAmx32w.mjs';
1
+ import { M as swapCtx, N as nullCtx, c as backpressure, I as IsStream, p as current, O as makeCtx, B as makeJob, h as isError, f as markHandled, d as detached, g as getJob, v as reject, b as resolve, P as freeCtx, l as callOrWait } from './call-or-wait-DpJBh_pS.mjs';
2
2
  import { b as batch, a as arrayEq, d as defer, c as apply, s as setMap, C as CallableObject } from './utils-P0JEpWXG.mjs';
3
3
 
4
4
  const ruleQueues = /* @__PURE__ */ new WeakMap();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uneventful",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "Declarative, event-driven reactivity: signals, streams, structured concurrency, and easy resource cleanup",
5
5
  "keywords": [
6
6
  "signals",
@@ -1 +0,0 @@
1
- {"version":3,"file":"call-or-wait-COAmx32w.mjs","sources":["../src/results.ts","../src/ambient.ts","../src/internals.ts","../src/chains.ts","../src/tracking.ts","../src/streams.ts","../src/jobutils.ts","../src/call-or-wait.ts"],"sourcesContent":["import { Job, Request } from \"./types.ts\";\n\n/**\n * Resolve a {@link Request} with a value.\n *\n * (For a curried version, see {@link resolver}.)\n *\n * @category Requests and Results\n */\nexport function resolve<T>(request: Request<T>, val: T) { request(\"next\", val); }\n\n/**\n * Reject a {@link Request} with a reason.\n *\n * (For a curried version, see {@link rejecter}.)\n *\n * @category Requests and Results\n */\nexport function reject(request: Request<any>, reason: any) { request(\"throw\", undefined, reason); }\n\n/**\n * Create a callback that will resolve the given {@link Request} with a value.\n *\n * @category Requests and Results\n */\nexport function resolver<T>(request: Request<T>): (val: T) => void { return request.bind(null, \"next\"); }\n\n/**\n * Create a callback that will reject the given {@link Request} with a reason.\n *\n * @category Requests and Results\n */\nexport function rejecter(request: Request<any>): (err: any) => void { return request.bind(null, \"throw\", undefined); }\n\n\n/**\n * A function that does nothing and returns void.\n *\n * @category Stream Consumers\n */\nexport function noop() {}\n\n/**\n * A {@link JobResult} that indicates the job was ended via a return() value.\n *\n * @category Types and Interfaces\n */\nexport type ValueResult<T> = {op: \"next\", val: T, err: undefined};\n\n/**\n * A {@link JobResult} that indicates the job was ended via a throw() or other\n * error.\n *\n * @category Types and Interfaces\n */\nexport type ErrorResult = UnhandledError | HandledError;\n\n/**\n * An {@link ErrorResult} that hasn't yet been \"handled\" (by being passed to an\n * error-specific handler, converted to a promise, given to {@link markHandled},\n * etc.)\n *\n * @category Types and Interfaces\n */\nexport type UnhandledError = {op: \"throw\", val: undefined, err: any};\n\n/**\n * An {@link ErrorResult} that has been marked \"handled\" (by being passed to an\n * error-specific handler, converted to a promise, given to {@link markHandled},\n * etc.)\n *\n * @category Types and Interfaces\n */\nexport type HandledError = {op: \"throw\", val: null, err: any};\n\n/**\n * A {@link JobResult} that indicates the job was canceled by its creator (via\n * end() or restart()).\n *\n * @category Types and Interfaces\n */\nexport type CancelResult = {op: \"cancel\", val: undefined, err: undefined};\n\n/**\n * A result passed to a job's cleanup callbacks, or supplied by its\n * .{@link Job.result result}() method.\n *\n * You can inspect a JobResult using functions like {@link isCancel}(),\n * {@link isError}(), and {@link isValue}(). {@link getResult}() can be used to\n * unwrap the value or throw the error.\n *\n * @category Types and Interfaces\n */\nexport type JobResult<T> = ValueResult<T> | ErrorResult | CancelResult ;\n\nfunction mkResult<T>(op: \"next\", val?: T): ValueResult<T>;\nfunction mkResult(op: \"throw\", val: undefined|null, err: any): ErrorResult;\nfunction mkResult(op: \"cancel\"): CancelResult;\nfunction mkResult<T>(op: string, val?: T, err?: any): JobResult<T> {\n return {op, val, err} as JobResult<T>\n}\n\n/**\n * The {@link JobResult} used to indicate a canceled job.\n *\n * @category Requests and Results\n */\nexport const CancelResult = Object.freeze(mkResult(\"cancel\"));\n\n/**\n * Create a {@link ValueResult} from a value\n *\n * @category Requests and Results\n */\nexport function ValueResult<T>(val: T): ValueResult<T> { return mkResult(\"next\", val); }\n\n/**\n * Create an {@link ErrorResult} from an error\n *\n * @category Requests and Results\n */\nexport function ErrorResult(err: any): UnhandledError { return mkResult(\"throw\", undefined, err); }\n\n/**\n * Returns true if the given result is a {@link CancelResult}.\n *\n * @category Requests and Results\n */\nexport function isCancel(res: JobResult<any> | undefined): res is CancelResult {\n return res === CancelResult;\n}\n\n/**\n * Returns true if the given result is a {@link ValueResult}.\n *\n * @category Requests and Results\n */\nexport function isValue<T>(res: JobResult<T> | undefined): res is ValueResult<T> {\n return res ? res.op === \"next\" : false;\n}\n\n/**\n * Returns true if the given result is a {@link ErrorResult}.\n *\n * @category Requests and Results\n */\nexport function isError(res: JobResult<any> | undefined): res is ErrorResult {\n return res ? res.op === \"throw\" : false;\n}\n\n/**\n * Returns true if the given result is an {@link UnhandledError}.\n *\n * @category Requests and Results\n */\nexport function isUnhandled(res: JobResult<any> | undefined): res is UnhandledError {\n return isError(res) && res.val === undefined;\n}\n\n/**\n * Returns true if the given result is a {@link HandledError} (an\n * {@link ErrorResult} that has been touched by {@link markHandled}).\n *\n * @category Requests and Results\n */\nexport function isHandled(res: JobResult<any> | undefined): res is HandledError {\n return isError(res) && res.val === null;\n}\n\n/**\n * Return the error of an {@link ErrorResult} and mark it as handled. The\n * {@link ErrorResult} is mutated in-place to become a {@link HandledError}.\n *\n * @category Requests and Results\n */\nexport function markHandled(res: ErrorResult): any {\n res.val = null;\n return res.err;\n}\n\n/**\n * Get the return value from a {@link JobResult}, throwing an appropriate error\n * if the result isn't a {@link ValueResult}.\n *\n * @param res The job result you want to unwrap. Must not be undefined!\n *\n * @returns The value if the result is a {@link ValueResult}, or a thrown error\n * if it's an {@link ErrorResult}. A {@link CancelError} is thrown if the job\n * was canceled, or the error in the result is thrown.\n *\n * If the result is an error, it is marked as handled.\n *\n * @category Jobs\n */\nexport function getResult<T>(res: JobResult<T>): T {\n if (isValue(res)) return res.val;\n res.op; // throw if not defined\n fulfillPromise(noop, e => { throw e; }, res);\n}\n\n/**\n * Fulfill a Promise from a {@link JobResult}\n *\n * If the result is a {@link CancelResult}, the promise is rejected with a\n * {@link CancelError}. Otherwise it is resolved or rejected according to the\n * state of the result.\n *\n * @param resolve A value-taking function (first arg to `new Promise` callback)\n *\n * @param reject An error-taking function (second arg to `new Promise` callback)\n *\n * @param res The job result you want to settle the promise with. An error will\n * be thrown if it's undefined.\n *\n * If the result is an error, it is marked as handled.\n *\n * @category Requests and Results\n */\nexport function fulfillPromise<T>(resolve: (v: T) => void, reject: (e: any) => void, res: JobResult<T>) {\n if (isError(res)) reject(markHandled(res));\n else if (isCancel(res)) reject(new CancelError(\"Job canceled\"));\n else resolve(res.val);\n}\n\n/**\n * Propagate a {@link JobResult} to another job\n *\n * If the result is a {@link CancelResult}, the job will throw with a\n * {@link CancelError}. Otherwise it is resolved or rejected according to the\n * state of the result.\n *\n * @param job The job to terminate. If it's already ended, nothing changes: the\n * result is not propagated and the error (if any) is not marked as handled.\n *\n * @param res The job result you want to settle the job with. An error will be\n * thrown if it's undefined. If the result is an error, it is marked as\n * handled.\n *\n * @category Requests and Results\n */\nexport function propagateResult<T>(job: Job<T>, res: JobResult<T>) {\n if (!job.result()) fulfillPromise(job.return.bind(job), job.throw.bind(job), res);\n}\n\n/**\n * Error thrown when waiting for a result from a job that is canceled.\n *\n * If you `await`, `yield *`, `.then()`, `.catch()`, {@link getResult}() or\n * otherwise wait on the result of a job that is canceled, this is the type\n * of error you'll get.\n *\n * @category Errors\n */\nexport class CancelError extends Error {}\n","/**\n * Ambient execution context (for job, resource, and dependency tracking)\n *\n * @internal\n * @module\n */\n\nimport type { Job } from \"./types.ts\";\nimport type { Cell } from \"./cells.ts\";\n\ntype Opt<X> = X | undefined | null;\n\nexport type Context = {\n job: Opt<Job<unknown>>\n cell: Opt<Cell>\n}\n\n/** The current context */\nexport var current: Context = makeCtx();\n\n\n/** Set a new current context, returning the old one */\nexport function swapCtx(future: Context): Context {\n const now = current;\n current = future;\n return now\n}\n\nvar freelist = [] as Context[];\n\n/** Get a fresh context object (either by creation or recycling) */\nexport function makeCtx(\n job?: Context[\"job\"],\n cell?: Context[\"cell\"],\n): Context {\n if (freelist && freelist.length) {\n const s = freelist.pop()!;\n s.job = job;\n s.cell = cell;\n return s;\n }\n return {job, cell};\n}\n\n/** Put a no-longer-needed context object on the recycling heap */\nexport function freeCtx(s: Context) {\n s.job = s.cell = null;\n freelist.push(s);\n}\n\n","/**\n * Provide access to certain internals (for testing use only)\n *\n * @module\n */\n\nimport { makeCtx } from \"./ambient.ts\";\nimport { batch } from \"./scheduling.ts\";\nimport { defer } from \"./defer.ts\";\nimport { Job } from \"./types.ts\";\n\nexport const\n /** Jobs' asyncCatch handlers: in a map because few jobs will have them */\n catchers = new WeakMap<Job, (this: Job, err: any) => unknown>(),\n\n /** Default error handler for the `detached` job */\n defaultCatch = (e: any) => { Promise.reject(e); }\n;\n\n/** A null context (no job/observer) for cleanups to run in */\nexport const nullCtx = makeCtx();\n\n/** Jobs' owners (parents) - uses a map so child jobs can't directly access them */\nexport const owners = new WeakMap<Job, Job>();\n\n/** Streams that need resuming */\nexport const pulls = /* @__PURE__ */ batch<{ doPull(): void; }>(pulls => {\n for (const conn of pulls) { pulls.delete(conn); conn.doPull(); }\n}, defer);\n","import { DisposeFn } from \"./types.ts\";\n\n/**\n * A counted, double-ended queue with the ability to undo insertions (even out\n * of order).\n *\n * @category Chains\n */\nexport type Chain<T, U=any> = Node<T, number, U>;\n\n/**\n * Create a new Chain\n *\n * @category Chains\n */\nexport function chain<T, U=DisposeFn>(): Chain<T, U> { return link<number, U>(0, undefined, undefined); }\n\n/**\n * Recycle a chain entirely - only safe if no references to it remain anywhere!\n */\nexport function recycle(c: Chain<any>) {\n while (c.v) unlink(c, c.n);\n c.u = undefined;\n unlink(c, c);\n}\n\n/**\n * Unshift a value onto the front of the chain\n *\n * @category Chains\n */\nexport function unshift<T>(c: Chain<T>, v: T) { ++c.v; link(v, c.n, c); }\n\n/**\n * Unshift a value onto the front of the chain, returning an undo callback. The\n * callback can be invoked to remove the value from the chain at any time, even\n * after other values have been added or removed. There is no effect if the\n * callback is run more than once, or if the value has already been removed.\n *\n * @category Chains\n */\nexport function unshiftCB<T>(c: Chain<T>, v: T) { ++c.v; return unlinker(c, link(v, c.n, c)); }\n\n/**\n * Push a value onto the end of the chain\n *\n * @category Chains\n */\nexport function push<T>(c: Chain<T>, v: T) { ++c.v; link(v, c, c.p); }\n\n/**\n * Push a value onto the end of the chain, returning an undo callback. The\n * callback can be invoked to remove the value from the chain at any time, even\n * after other values have been added or removed. There is no effect if the\n * callback is run more than once, or if the value has already been removed.\n *\n * @category Chains\n */\nexport function pushCB<T>(c: Chain<T>, v: T) { ++c.v; return unlinker(c, link(v, c, c.p)); }\n\n/**\n * Return true if the chain is empty, or is null/undefined\n *\n * @category Chains\n */\nexport function isEmpty(c: Chain<any> | null | undefined) { return !c || c.v === 0; }\n\n/**\n * Return the number of items in the chain, or 0 if it's null/undefined\n *\n * @category Chains\n */\nexport function qlen(c: Chain<any> | null | undefined) { return c ? c.v : 0; }\n\n/**\n * Remove a value from the end of the chain, returning it\n *\n * @category Chains\n */\nexport function pop<T>(c: Chain<T>) { if (qlen(c)) return unlink(c, c.p); }\n\n/**\n * Remove a value from the front of the chain, returning it\n *\n * @category Chains\n */\nexport function shift<T>(c: Chain<T>) { if (qlen(c)) return unlink(c, c.n); }\n\n/** A node in a chain */\nclass Node<T, V=T, U=DisposeFn> {\n /** The next node (or the start node if this is a chain head) */\n n: Node<T> = this as Node<T, any>;\n /** The previous node (or the end node if this is a chain head) */\n p: Node<T> = this as Node<T, any>;\n /** The value held by the node (or the chain length if this is a chain head) */\n v: V = undefined;\n /** The most recently created undo callback for this node */\n u: U = undefined;\n}\n\n/** Recycling list for chain nodes, to reduce constructor/alloc overhead */\nvar free: Node<any,any,any>;\n\n/** Create (or reuse) a node with a given value, inserting it between two nodes in a chain */\nfunction link<T,U=DisposeFn>(v: T, n: Node<T, any, any>, p: Node<T, any, any>): Node<T,T,U> {\n let node: Node<T, T, any> = free;\n if (node) {\n free = node.n;\n node.n = n || node;\n node.p = p || node;\n } else {\n node = new Node<T, T, U>;\n if (n) node.n = n;\n if (p) node.p = p;\n }\n node.v = v;\n node.n.p = node;\n node.p.n = node;\n return node;\n}\n\n/** Unlink a node from a chain and recycle it, returning the value it held */\nfunction unlink<T>(c: Chain<any>, node: Node<T>) {\n --c.v;\n var v = node.v, u = node.u;\n node.n && (node.n.p = node.p);\n node.p && (node.p.n = node.n);\n node.u = node.v = node.p = undefined;\n node.n = free; free = node;\n if (u) u(); // drop refs to node+chain\n return v;\n}\n\n/**\n * Return an undo/remove callback that will run at most once and is a no-op if the\n * node was already removed. If called more than once on the same node while\n * it's in the same chain, it returns the same callback. ()\n */\nfunction unlinker(chain: Chain<any>, node: Node<any>) {\n let u = (node.u ||= () => {\n if (u) {\n // If the node's undo callback is this callback, then it's safe to remove;\n // otherwise, the node has already been removed and/or recycled for use in\n // a different chain (or a different value in this one!)\n if (u === node.u) unlink(chain, node);\n u = chain = node = undefined;\n }\n })\n return u;\n}\n","import { makeCtx, current, freeCtx, swapCtx } from \"./ambient.ts\";\nimport { catchers, defaultCatch, nullCtx, owners } from \"./internals.ts\";\nimport { CleanupFn, Job, Request, Yielding, Suspend, PlainFunction, StartFn, OptionalCleanup, JobIterator, RecalcSource, StartObj } from \"./types.ts\";\nimport { defer } from \"./defer.ts\";\nimport { JobResult, ErrorResult, CancelResult, isCancel, ValueResult, isError, isValue, noop, markHandled, isUnhandled, propagateResult } from \"./results.ts\";\nimport { rejecter, resolver, getResult, fulfillPromise } from \"./results.ts\";\nimport { Chain, chain, isEmpty, pop, push, pushCB, qlen, recycle, unshift } from \"./chains.ts\";\nimport { Stream, Sink, Inlet, Connection } from \"./streams.ts\";\nimport { GeneratorBase, apply } from \"./utils.ts\";\nimport { isFunction } from \"./utils.ts\";\n\n/**\n * Return the currently-active Job, or throw an error if none is active.\n *\n * (You can check if a job is active first using {@link isJobActive}().)\n *\n * @category Jobs\n */\nexport function getJob<T=unknown>() {\n const job = current.job || current.cell?.getJob();\n if (job) return job as Job<T>;\n throw new Error(\"No job is currently active\");\n}\n\n/** RecalcSource factory for jobs (so you can wait on a job result in a signal or rule) */\nfunction recalcJob(job: Job<any>): RecalcSource { return (cb => { current.job.must(job.release(cb)); }); }\n\nfunction runChain<T>(res: JobResult<T>, cbs: Chain<CleanupFn<T>>): undefined {\n while (qlen(cbs)) try { pop(cbs)(res); } catch (e) { detached.asyncThrow(e); }\n cbs && recycle(cbs);\n return undefined;\n}\n\n// The set of jobs whose callbacks need running during an end() sweep\nvar inProcess = new Set<_Job<any>>;\n\nclass _Job<T> implements Job<T> {\n /** @internal */\n static create<T>(parent?: Job, stop?: CleanupFn): Job<T> {\n const job = new _Job<T>;\n if (parent || stop) {\n job.must((parent ||= getJob()).release(stop || job.end));\n owners.set(job, parent);\n }\n return job;\n }\n\n do(cleanup: CleanupFn<T>): this {\n unshift(this._chain(), cleanup);\n return this;\n }\n\n onError(cb: (err: any) => unknown): this {\n return this.do(r => { if (isError(r)) cb(markHandled(r)); });\n }\n\n onValue(cb: (val: T) => unknown): this {\n return this.do(r => { if (isValue(r)) cb(r.val); });\n }\n\n onCancel(cb: () => unknown): this {\n return this.do(r => { if (isCancel(r)) cb(); });\n }\n\n result(): JobResult<T> | undefined {\n // If we're done, we're done; otherwise make signals/rules reading this\n // recalc when we're done (handy for rendering \"loading\" states).\n return this._done || current.cell?.recalcWhen(this, recalcJob) || undefined;\n }\n\n get [Symbol.toStringTag]() { return \"Job\"; }\n\n end = () => {\n const res = (this._done ||= CancelResult), cbs = this._cbs;\n // if we have an unhandled error, fall through to queued mode for later\n // re-throw; otherwise, if there aren't any callbacks we're done here\n if (!cbs && !isUnhandled(res)) return;\n\n const ct = inProcess.size, old = swapCtx(nullCtx);;\n // Put a placeholder on the queue if it's empty\n if (!ct) inProcess.add(null);\n\n // Give priority to the release() chain so we get breadth-first flagging\n // of all child jobs as canceled immediately\n if (cbs && cbs.u) cbs.u = runChain(res, cbs.u);\n\n // Put ourselves on the queue *after* our children, so their cleanups run first\n inProcess.add(this);\n\n // if the queue wasn't empty, there's a loop above us that will run our must/do()s\n if (ct) { swapCtx(old); return; }\n\n // don't need the placeholder any more\n inProcess.delete(null);\n\n // Queue was empty, so it's up to us to run everybody's must/do()s\n for (const item of inProcess) {\n if (item._cbs) item._cbs = runChain(item._done, item._cbs);\n inProcess.delete(item);\n if (isUnhandled(item._done)) item.throw(markHandled(item._done));\n }\n swapCtx(old);\n }\n\n restart() {\n if (!this._done && inProcess.size) {\n // if a tree of jobs is ending right now, we need to start\n // a new stack so that when we return, all our children's\n // callbacks will have finished running first.\n const old = inProcess;\n inProcess = new Set;\n this.end();\n inProcess = old;\n } else {\n this._end(CancelResult);\n }\n this._done = undefined;\n promises.delete(this); // don't reuse any now-cancelled promise!\n return this;\n }\n\n _end(res: JobResult<T>) {\n if (this._done) throw new Error(\"Job already ended\");\n if (this !== detached) this._done = res;\n this.end();\n return this;\n }\n\n throw(err: any) {\n if (this._done) {\n (owners.get(this) || detached).asyncThrow(err);\n return this;\n }\n return this._end(ErrorResult(err));\n }\n\n return(val: T) { return this._end(ValueResult(val)); }\n\n then<T1=T, T2=never>(\n onfulfilled?: (value: T) => T1 | PromiseLike<T1>,\n onrejected?: (reason: any) => T2 | PromiseLike<T2>\n ): Promise<T1 | T2> {\n return nativePromise(this).then(onfulfilled, onrejected);\n }\n\n catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<T | TResult> {\n return nativePromise(this).catch(onrejected);\n }\n\n finally(onfinally?: () => void): Promise<T> {\n return nativePromise(this).finally(onfinally);\n }\n\n *[Symbol.iterator](): JobIterator<T> {\n if (this._done) {\n return getResult(this._done);\n } else return yield (req: Request<T>) => {\n // XXX should this be a release(), so if the waiter dies we\n // don't bother? The downside is that it'd have to be mutual and\n // the resume is a no-op anyway in that case.\n this.do(res => fulfillPromise(resolver(req), rejecter(req), res));\n }\n }\n\n start<T>(fn?: StartFn<T> | StartObj<T>): Job<T>;\n start<T, This>(ctx: This, fn: StartFn<T, This>): Job<T>;\n start<T, This>(fnOrCtx: StartFn<T> | StartObj<T>|This, fn?: StartFn<T, This>) {\n if (!fnOrCtx) return makeJob(this);\n let init: StartFn<T, This>, result: StartObj<T> | OptionalCleanup;\n if (isFunction(fn)) {\n init = fn.bind(fnOrCtx as This);\n } else if (isFunction(fnOrCtx)) {\n init = fnOrCtx as StartFn<T, This>;\n } else if (fnOrCtx instanceof _Job) {\n return fnOrCtx;\n } else {\n result = fnOrCtx as StartObj<T>;\n }\n const job = makeJob<T>(this);\n try {\n if (init) result = job.run(init as StartFn<T>, job);\n if (result != null) {\n if (isFunction(result)) {\n job.must(result);\n } else if (result instanceof GeneratorBase) {\n job.run(runGen<T>, result as Yielding<T>, job);\n } else if (result instanceof _Job) {\n if (result !== job) result.do(res => propagateResult(job, res));\n } else if (result instanceof Promise) {\n // Duplicated because this will be monomorphic or low-poly,\n // but next branch will always be megamorphic\n (result as Promise<T>).then(\n v => { job.result() || job.return(v); },\n e => { job.result() || job.throw(e); }\n );\n } else if (isFunction((result as Promise<T>).then)) {\n (result as Promise<T>).then(\n v => { job.result() || job.return(v); },\n e => { job.result() || job.throw(e); }\n );\n } else if (\n isFunction((result as Yielding<T>)[Symbol.iterator]) &&\n typeof result !== \"string\"\n ) {\n job.run(runGen<T>, result as Yielding<T>, job);\n } else {\n throw new TypeError(\"Invalid value/return for start()\");\n }\n }\n return job;\n } catch(e) {\n job.end();\n throw e;\n }\n }\n\n connect<T>(src: Stream<T>, sink: Sink<T>, inlet?: Inlet): Connection {\n return this.start(job => void src(sink, job, inlet));\n }\n\n protected constructor() {};\n\n run<F extends PlainFunction>(fn: F, ...args: Parameters<F>): ReturnType<F> {\n const old = swapCtx(makeCtx(this));\n try { return fn(...args); } finally { freeCtx(swapCtx(old)); }\n }\n\n bind<F extends (...args: any[]) => any>(fn: F): F {\n const job = this;\n return <F> function (this: any) {\n const old = swapCtx(makeCtx(job));\n try { return apply(fn, this, arguments); } finally { freeCtx(swapCtx(old)); }\n }\n }\n\n must(cleanup?: OptionalCleanup) {\n if (isFunction(cleanup)) push(this._chain(), cleanup);\n return this;\n }\n\n release(cleanup: CleanupFn): () => void {\n if (this === detached) return noop;\n let cbs = this._chain();\n if (!this._done || cbs.u) cbs = cbs.u ||= chain();\n return pushCB(cbs, cleanup);\n }\n\n asyncThrow(err: any) {\n try {\n (catchers.get(this) || this.throw).call(this, err);\n } catch (e) {\n // Don't allow a broken handler to stay on the job\n if (this === detached) catchers.set(this, defaultCatch); else catchers.delete(this);\n const catcher = catchers.get(this) || this.throw;\n catcher.call(this, err);\n catcher.call(this, e); // also report the broken handler\n }\n return this;\n }\n\n asyncCatch(handler: ((this: Job, err: any) => unknown) | null): this {\n if (isFunction(handler)) catchers.set(this, handler);\n else if (handler === null) catchers.delete(this);\n return this;\n }\n\n protected _done: JobResult<T> = undefined;\n\n // Chain whose .u stores a second chain for `release()` callbacks\n protected _cbs: Chain<CleanupFn<T>, Chain<CleanupFn<T>>> = undefined;\n protected _chain() {\n if (this === detached) this.end()\n if (this._done && isEmpty(this._cbs)) defer(this.end);\n return this._cbs ||= chain();\n }\n}\n\nconst promises = new WeakMap<Job<any>, Promise<any>>();\n\n/**\n * Obtain a native promise for a job\n *\n * While jobs have the same interface as native promises, there are occasionally\n * reasons to just use one directly. (Like when Uneventful uses this function\n * to implement jobs' promise methods!)\n *\n * @param job The job to get a native promise for.\n *\n * @returns A {@link Promise} that resolves or rejects according to whether the\n * job returns or throws. If the job is canceled, the promise is rejected with\n * a {@link CancelError}.\n *\n * @category Jobs\n */\nexport function nativePromise<T>(job: Job<T>): Promise<T> {\n if (!promises.has(job)) {\n promises.set(job, new Promise((res, rej) => {\n const toPromise = (fulfillPromise<T>).bind(null, res, rej);\n if (job.result()) toPromise(job.result()); else job.do(toPromise);\n }));\n }\n return promises.get(job);\n}\n\n/**\n * Return a new {@link Job}. If *either* a parent parameter or stop function\n * are given, the new job is linked to the parent.\n *\n * @param parent The parent job to which the new job should be attached.\n * Defaults to the currently-active job if none given (assuming a stop\n * parameter is provided).\n *\n * @param stop The function to call to destroy the nested job. Defaults to the\n * {@link Job.end} method of the new job if none is given (assuming a parent\n * parameter is provided).\n *\n * @returns A new job. The job is linked/nested if any arguments are given,\n * or a detached (parentless) job otherwise.\n *\n * @category Jobs\n */\nexport const makeJob: <T>(parent?: Job, stop?: CleanupFn) => Job<T> = _Job.create;\n\n/**\n * A special {@link Job} with no parents, that can be used to create standalone\n * jobs. detached.start() returns a new detached job, detached.run() can be\n * used to run code that expects to create a child job, and detached.bind() can\n * wrap a function to work without a parent job.\n *\n * (Note that such `detached` child jobs *must* exit themselves or be stopped\n * explicitly from outside, or else they may \"run\" forever, never running their\n * cleanup callbacks. Unlike other jobs, they don't end when their parent does\n * because the `detached` job never \"ends\".)\n *\n * The detached job has a few special features and limitations:\n *\n * - It can't be ended, thrown, return()ed, etc. -- you'll get an error\n *\n * - It can't have any cleanup functions added: no do, must, onError, etc., and\n * thus also can't have any native promise, abort signal, etc. used. You can\n * call its release() method, but nothing will actually be registered and the\n * returned callback is a no-op.\n *\n * - Unhandled errors from jobs without parents (and errors from *any* job's\n * cleanup functions) are sent to the detached job for handling. This means\n * whatever you set as the detached job's .{@link Job.asyncCatch asyncCatch}()\n * handler will receive them. (Its default is Promise.reject, causing an\n * unhandled promise rejection.)\n *\n * @category Jobs\n */\nexport const detached = makeJob();\n(detached as any).end = () => { throw new Error(\"Can't do that with the detached job\"); }\ndetached.asyncCatch(defaultCatch);\n\nfunction runGen<R>(g: Yielding<R>, job: Job<R>) {\n let it = g[Symbol.iterator](), running = true, ctx = makeCtx(job), ct = 0;\n let done = ctx.job.release(() => {\n job = undefined;\n ++ct; // disable any outstanding request(s)\n // XXX this should be deferred to cleanup phase, or must() instead of release\n // (release only makes sense here if you can run more than one generator in a job)\n step(\"return\", undefined);\n });\n // Start asynchronously\n defer(() => { running = false; step(\"next\", undefined); });\n\n function step(method: \"next\" | \"throw\" | \"return\", arg: any): void {\n if (!it) return;\n // Don't resume a job while it's running\n if (running) {\n return defer(step.bind(null, method, arg));\n }\n const old = swapCtx(ctx);\n try {\n running = true;\n try {\n for(;;) {\n ++ct;\n const {done, value} = it[method](arg);\n if (done) {\n job && job.return(value);\n job = undefined;\n break;\n } else if (!isFunction(value)) {\n method = \"throw\";\n arg = new TypeError(\"Jobs must yield functions (or yield* Yielding<T>s)\");\n continue;\n } else {\n let called = false, returned = false, count = ct;\n (value as Suspend<any>)((op, val, err) => {\n if (called) return; else called = true;\n method = op; arg = op === \"next\" ? val : err;\n if (returned && count === ct) step(op, arg);\n });\n returned = true;\n if (!called) return;\n }\n }\n } catch(e) {\n it = job = undefined;\n ctx.job.throw(e);\n }\n // Iteration is finished; disconnect from job\n it = undefined;\n done?.();\n done = undefined;\n } finally {\n swapCtx(old);\n running = false;\n }\n }\n}\n","import { pulls } from \"./internals.ts\";\nimport { DisposeFn, Job } from \"./types.ts\";\nimport { getJob } from \"./tracking.ts\";\nimport { current } from \"./ambient.ts\";\n\n/**\n * A backpressure controller: returns true if downstream is ready to accept\n * data.\n *\n * @param cb (optional) - a callback to run when the downstream consumer wishes\n * to resume event production (i.e., when a sink calls\n * {@link Throttle.resume}()). The callback is automatically unregistered when\n * invoked, so the producer must re-register it after each call if it wishes to\n * keep being called.\n *\n * @category Types and Interfaces\n */\nexport type Backpressure = (cb?: () => any) => boolean\n\n\n/**\n * Create a backpressure control function for the given connection\n *\n * @category Stream Producers\n */\nexport function backpressure(inlet: Inlet = defaultInlet): Backpressure {\n const job = getJob();\n return (cb?: Flush) => {\n if (!job.result() && inlet.isOpen()) {\n if (cb) inlet.onReady(cb, job);\n return inlet.isReady();\n }\n return false;\n }\n}\n\n/**\n * Control backpressure for listening streams. This interface is the API\n * internal to the implementation of {@link backpressure}(). Unless you're\n * implementing a backpressurable stream yourself, see the {@link Throttle}\n * interface instead.\n *\n * @category Types and Interfaces\n */\nexport interface Inlet {\n /** Is the main connection open? (i.e. is the creating job not closed yet?) */\n isOpen(): boolean\n\n /** Is the connection ready to receive data? */\n isReady(): boolean\n\n /**\n * Register a callback to produce more data when the inlet is resumed\n * (The callback is unregistered if the supplied job ends.)\n */\n onReady(cb: () => any, job: Job): this;\n}\n\n/**\n * Control backpressure for listening streams\n *\n * Obtain instances via {@link throttle}(), then pass them into the appropriate\n * stream-consuming API. (e.g. {@link connect}).\n *\n * @category Types and Interfaces\n */\nexport interface Throttle extends Inlet {\n /** Set inlet status to \"paused\". */\n pause(): void;\n\n /**\n * Un-pause, and iterate backpressure-able sources' onReady callbacks to\n * resume sending immediately. (i.e., synchronously!)\n */\n resume(): void;\n}\n\n/**\n * A Connection is a job that returns void when the connected stream ends\n * itself. If the stream doesn't end itself (e.g. it's an event listener), the\n * job will never return, and only end with a cancel or throw.\n *\n * @category Types and Interfaces\n */\nexport type Connection = Job<void>;\n\n/**\n * A Source is a function that can be called to arrange for data to be\n * produced and sent to a {@link Sink} function for consumption, until the\n * associated {@link Connection} is closed (either by the source or the sink,\n * e.g. if the sink doesn't want more data or the source has no more to send).\n *\n * If the source is a backpressurable stream, it can use the (optional) supplied\n * inlet (usually a {@link throttle}()) to rate-limit its output.\n *\n * A producer function *must* return the special {@link IsStream} value, so\n * TypeScript can tell what functions are usable as sources. (Otherwise any\n * void function with no arguments would appear to be usable as a source!)\n *\n * @category Types and Interfaces\n */\nexport interface Source<T> {\n /** Subscribe sink to receive values */\n (sink: Sink<T>, conn?: Connection, inlet?: Throttle | Inlet): typeof IsStream;\n}\n\n/**\n * An uneventful stream is either a {@link Source} or a {@link SignalSource}.\n * (Signals actually implement the {@link Source} interface as an overload, but\n * TypeScript gets confused about that sometimes, so we generally declare our\n * stream *inputs* as `Stream<T>` and our stream *outputs* as {@link Source}, so\n * that TypeScript knows what's what.\n *\n * @category Types and Interfaces\n */\nexport type Stream<T> = Source<T> | SignalSource<T>;\n\n/**\n * The call signatures implemented by signals. (They can be used as sources, or\n * called with no arguments to return a value.)\n *\n * This type is needed because TypeScript won't infer the overloads of\n * {@link Signal} correctly otherwise. (Specifically, it won't allow it to be\n * used as a zero-agument function.)\n *\n * @category Types and Interfaces\n*/\nexport type SignalSource<T> = Source<T> & {\n /** A signal object can be called to get its current value */\n (): T\n}\n\n/**\n * A specially-typed string used to verify that a function supports uneventful's\n * streaming protocol. Return it from a function to implement the\n * {@link Source} type.\n *\n * @category Types and Interfaces\n */\nexport const IsStream = \"uneventful/is-stream\" as const;\n\n/**\n * A `Sink` is a function that receives data from a {@link Stream}.\n *\n * @category Types and Interfaces\n */\nexport type Sink<T> = (val: T) => void;\n\n/**\n * A `Transformer` is a function that takes one stream and returns another,\n * possibly one that produces data of a different type. Most operator functions\n * return a transformer, allowing them to be combined via {@link pipe}().\n *\n * @category Types and Interfaces\n */\nexport type Transformer<T, V=T> = (input: Stream<T>) => Source<V>;\n\ntype Flush = () => any\n\n\n/**\n * Subscribe a sink to a stream, returning a nested job. (Shorthand for\n * .{@link Job.connect connect}(...) on the active job.)\n *\n * @param src An event source or signal\n * @param sink A callback that will receive the events\n * @param inlet Optional - a {@link throttle}() to control backpressure\n *\n * @returns A job that can be aborted to end the subscription, and which will\n * end naturally (with a void return or error) if the stream ends itself.\n *\n * @category Stream Consumers\n */\nexport function connect<T>(src: Stream<T>, sink: Sink<T>, inlet?: Throttle | Inlet): Connection {\n return getJob().connect(src, sink, inlet);\n}\n\n/**\n * Create a backpressure controller for a stream. Pass it to one or more\n * sources you're connecting to, and if they support backpressure they'll\n * respond when you call its .pause() and .resume() methods.\n *\n * @param job - Optional: a job that controls readiness. (The throttle will\n * pause indefinitely when the job ends.) Defaults to the currently-active job,\n * but unlike most such defaults, it won't throw if no job is active.\n *\n * @category Stream Consumers\n */\nexport function throttle(job: Job = current.job): Throttle {\n return new _Throttle(job);\n}\n\nclass _Throttle implements Throttle {\n /** @internal */\n protected _callbacks: Map<Flush, DisposeFn> = undefined;\n\n /** @internal */\n constructor(protected _job?: Job) {}\n\n isOpen(): boolean { return !this._job?.result(); }\n\n /** Is the connection ready to receive data? */\n isReady(): boolean { return this.isOpen() && this._isReady; }\n\n _isReady = true;\n _isPulling = false;\n\n onReady(cb: Flush, job: Job) {\n if (!this.isOpen()) return this;\n const _callbacks = (this._callbacks ||= new Map);\n const unlink = job.release(() => _callbacks.delete(cb));\n if (this.isReady() && this && !_callbacks.size) {\n pulls.add(this);\n }\n _callbacks.set(cb, unlink);\n return this;\n }\n\n pause() { this._isReady = false; return this; }\n\n doPull() {\n if (this._isPulling) return;\n const {_callbacks} = this;\n if (!_callbacks?.size) return;\n this._isPulling = true;\n try {\n for(let [cb, unlink] of _callbacks) {\n if (!this.isReady()) break; // we're done\n unlink()\n _callbacks.delete(cb);\n cb() // XXX error handling?\n }\n } finally {\n this._isPulling = false;\n }\n }\n\n resume() {\n if (this.isOpen()) {\n this._isReady = true;\n this.doPull();\n }\n }\n}\n\nconst defaultInlet: Inlet = throttle();\n\n/**\n * Pipe a stream (or anything else) through a series of single-argument\n * functions/operators\n *\n * e.g. the following creates a stream that outputs 4 and then 6:\n *\n * ```ts\n * pipe(fromIterable([1,2,3,4]), skip(1), take(2), map(x => x*2))\n * ```\n *\n * The first argument to pipe() can be any value, but all other arguments must\n * be functions. The value is passed to the first function, and then the result\n * is passed to the next function in turn, until all provided functions have\n * been called with the result of the previous function. The return value is\n * the last result, or the original value if no functions were given.\n *\n * The underlying implementation of pipe() works with any number of arguments,\n * but due to TypeScript limitations we only have typing defined for a max of 9\n * functions (10 arguments total). If you need more than 9 functions, you can\n * stack some of them with {@link compose}(), e.g.:\n *\n * ```typescript\n * pipe(\n * aStream,\n * compose(op1, op2, ...),\n * compose(op10, op11, ...),\n * compose(op19, ...),\n * ...\n * )\n * ```\n *\n * @category Stream Operators\n */\nexport function pipe<A,B,C,D,E,F,G,H,I,J>(input: A, ...fns: Chain9<A,J,B,C,D,E,F,G,H,I>): J\nexport function pipe<A,B,C,D,E,F,G,H,I> (input: A, ...fns: Chain8<A,I,B,C,D,E,F,G,H>): I\nexport function pipe<A,B,C,D,E,F,G,H> (input: A, ...fns: Chain7<A,H,B,C,D,E,F,G>): H\nexport function pipe<A,B,C,D,E,F,G> (input: A, ...fns: Chain6<A,G,B,C,D,E,F>): G\nexport function pipe<A,B,C,D,E,F> (input: A, ...fns: Chain5<A,F,B,C,D,E>): F\nexport function pipe<A,B,C,D,E> (input: A, ...fns: Chain4<A,E,B,C,D>): E\nexport function pipe<A,B,C,D> (input: A, ...fns: Chain3<A,D,B,C>): D\nexport function pipe<A,B,C> (input: A, ...fns: Chain2<A,C,B>): C\nexport function pipe<A,B> (input: A, ...fns: Chain1<A,B>): B\nexport function pipe<A> (input: A): A\nexport function pipe(input: any, ...fns: Array<(v: any) => any>): any;\nexport function pipe<A,X>(): X {\n var v = arguments[0];\n for (var i=1; i<arguments.length; i++) v = arguments[i](v);\n return v;\n}\n\n/**\n * Compose a series of single-argument functions/operators in application order.\n * (This is basically a deferred version of {@link pipe}().) For example:\n *\n * ```ts\n * const func = compose(skip(1), take(2), map(x => x*2));\n * const stream_4_6 = func(fromIterable([1,2,3,4])); // stream that outputs 4, 6\n * ```\n *\n * As with `pipe()`, the declared typings only support composing up to 9\n * functions at once; if you need more you'll need to nest calls to `compose()`\n * (i.e. passing the result of a `compose()` as an argument to another\n * `compose()` call.)\n *\n * @returns A function taking the same type as the first input function,\n * returning the same type as the last input function.\n *\n * @category Stream Operators\n */\nexport function compose<A,B,C,D,E,F,G,H,I,J>(...fns: Chain9<A,J,B,C,D,E,F,G,H,I>): (a: A) => J\nexport function compose<A,B,C,D,E,F,G,H,I> (...fns: Chain8<A,I,B,C,D,E,F,G,H>): (a: A) => I\nexport function compose<A,B,C,D,E,F,G,H> (...fns: Chain7<A,H,B,C,D,E,F,G>): (a: A) => H\nexport function compose<A,B,C,D,E,F,G> (...fns: Chain6<A,G,B,C,D,E,F>): (a: A) => G\nexport function compose<A,B,C,D,E,F> (...fns: Chain5<A,F,B,C,D,E>): (a: A) => F\nexport function compose<A,B,C,D,E> (...fns: Chain4<A,E,B,C,D>): (a: A) => E\nexport function compose<A,B,C,D> (...fns: Chain3<A,D,B,C>): (a: A) => D\nexport function compose<A,B,C> (...fns: Chain2<A,C,B>): (a: A) => C\nexport function compose<A,B> (...fns: Chain1<A,B>): (a: A) => B\nexport function compose<A> (): (a: A) => A\nexport function compose(...fns: ((v:any)=>any)[]) {\n return (val:any) => (pipe as any)(val, ...fns);\n}\n\ntype Chain1<A,R> = [(v: A) => R];\ntype Chain2<A,R,B> = [...Chain1<A,B>, ...Chain1<B,R>];\ntype Chain3<A,R,B,C> = [...Chain1<A,B>, ...Chain2<B,R,C>];\ntype Chain4<A,R,B,C,D> = [...Chain1<A,B>, ...Chain3<B,R,C,D>];\ntype Chain5<A,R,B,C,D,E> = [...Chain1<A,B>, ...Chain4<B,R,C,D,E>];\ntype Chain6<A,R,B,C,D,E,F> = [...Chain1<A,B>, ...Chain5<B,R,C,D,E,F>];\ntype Chain7<A,R,B,C,D,E,F,G> = [...Chain1<A,B>, ...Chain6<B,R,C,D,E,F,G>];\ntype Chain8<A,R,B,C,D,E,F,G,H> = [...Chain1<A,B>, ...Chain7<B,R,C,D,E,F,G,H>];\ntype Chain9<A,R,B,C,D,E,F,G,H,I> = [...Chain1<A,B>, ...Chain8<B,R,C,D,E,F,G,H,I>];\n\n/**\n * Pass subscriber into a stream (or any arguments into any other function).\n *\n * This utility is mainly here for uses like:\n *\n * - `pipe(src, into(sink))`,\n * - `pipe(src, into(sink, conn))`,\n * - `pipe(src, into(restarting(sink)))`, etc.\n *\n * but can also be used for argument currying generally.\n *\n * @param args The arguments to pass to the stream (or other function)\n *\n * @returns a function that takes another function and calls it with the given args.\n *\n * @category Stream Consumers\n */\nexport function into<In extends any[], Out>(...args: In): (src: (...args: In) => Out) => Out {\n return src => src(...args);\n}\n","import { current, freeCtx, makeCtx, swapCtx } from \"./ambient.ts\";\nimport { getJob, makeJob } from \"./tracking.ts\";\nimport { AnyFunction, CleanupFn, Job, OptionalCleanup, StartFn, StartObj, Yielding } from \"./types.ts\";\nimport { apply } from \"./utils.ts\";\n\n/**\n * Add a cleanup function to the active job. Non-function values are ignored.\n * Equivalent to calling .{@link Job.must must}() on the current job. (See\n * {@link Job.must}() for more details.)\n *\n * @category Jobs\n */\nexport function must(cleanup?: OptionalCleanup): void {\n getJob().must(cleanup);\n}\n\n/**\n * Start a nested job within the currently-active job. (Shorthand for\n * calling .{@link Job.start start}(...) on the active job.)\n *\n * This function can be called with zero, one, or two arguments:\n *\n * - When called with zero arguments, the new job is returned without any other\n * initialization.\n *\n * - When called with one argument that's a function (either a {@link SyncStart}\n * or {@link AsyncStart}): the function is run inside the new job and receives\n * it as an argument. It can return a {@link Yielding} iterator (such as a\n * generator or job), a promise, or void. A returned iterator or promise will\n * be treated as if the method was called with that to begin with; a returned\n * job will be awaited and its result transferred to the new job\n * asynchronously. A returned function will be added to the job via `must()`.\n *\n * - When called with one argument that's a {@link Yielding} iterator (such as a\n * generator or an existing job): it's attached to the new job and executed\n * asynchronously. (Starting in the next available microtask.)\n *\n * - When called with one argument that's a Promise, it's converted to a job\n * that will end when the promise settles. The resulting job is returned.\n *\n * - When called with two arguments -- a \"this\" object and a function -- it\n * works the same as one argument that's a function, except the function is\n * bound to the supplied \"this\" before being called.\n *\n * This last signature is needed because you can't make generator arrows in JS\n * yet: if you want to start() a generator function bound to the current\n * `this`, you'll want to use `.start(this, function*() { ...whatever })`.\n *\n * (Note, however, that TypeScript and/or VSCode may require that you give\n * such a function an explicit `this` parameter (e.g. `.start(this, function\n * *(this) {...}));`) in order to correctly infer types inside a generator\n * function.)\n *\n * In any of the above cases, if a supplied function throws an error while\n * starting, the new job will be ended, and the error synchronously re-thrown.\n *\n * @returns the created {@link Job}\n *\n * @category Jobs\n */\nexport function start<T>(init?: StartFn<T> | StartObj<T>): Job<T>;\n\n/**\n * The two-argument variant of start() allows you to pass a \"this\" object that\n * will be bound to the initialization function. (It's mostly useful for\n * generator functions, since generator arrows aren't a thing yet.)\n */\nexport function start<T, This>(thisArg: This, fn: StartFn<T, This>): Job<T>;\nexport function start<T, This>(init: StartFn<T>|StartObj<T>|This, fn?: StartFn<T, This>) {\n return getJob().start(init as This, fn);\n}\n\n/**\n * Is there a currently active job? (i.e., can you safely use {@link must}(),\n * or {@link getJob}() right now?)\n *\n * @category Jobs\n */\nexport function isJobActive() { return !!current.job; }\n\n\nconst timers = new WeakMap<Job,\n ReturnType<typeof setTimeout> | // current timeout\n undefined | // no timeout set since job was last restarted (if ever)\n null // current timeout is 0, aka explicit no-timeout\n>();\n\n/**\n * Set the cancellation timeout for a job.\n *\n * When the timeout is reached, the job is canceled (throwing\n * {@link CancelError} to any waiting promises or jobs), unless a new timeout\n * is set before then. You may set a new timeout value for a job as many times\n * as desired. A timeout value of zero disables the timeout. Timers are\n * disposed of if the job is canceled or restarted.\n *\n * @param ms Optional: Number of milliseconds after which the job will be\n * canceled. Defaults to zero if not given.\n *\n * @param job Optional: the job to apply the timeout to. If none is given, the\n * active job is used.\n *\n * @returns the job to which the timeout was added or removed.\n *\n * @category Scheduling\n */\nexport function timeout<T>(ms: number, job?: Job<T>): Job<T>;\nexport function timeout(ms = 0, job: Job = getJob()) {\n let timer = timers.get(job);\n if (timer) {\n clearTimeout(timer);\n } else if (timer === undefined && !job.result()) {\n // no timeout has been set since job was last restarted,\n // so we need to arrange to clear it\n job.must(timeout.bind(null, 0, job));\n }\n if (job.result()) {\n // allow restarted timer to set a new must()\n timers.delete(job);\n } else if (ms) {\n timers.set(job, setTimeout(() => { timers.set(job, null); job.end(); }, ms));\n } else {\n timers.set(job, null); // Zero = cancel timeout, but don't duplicate must() if called again\n }\n return job;\n}\n\nconst abortSignals = new WeakMap<Job, AbortSignal>();\n\n/**\n * Get an AbortSignal that aborts when the job ends or is restarted.\n *\n * @param job Optional: the job to get an AbortSignal for. If none is given,\n * the active job is used.\n *\n * @returns the AbortSignal\n *\n * @category Jobs\n */\nexport function abortSignal(job: Job = getJob()) {\n let signal = abortSignals.get(job);\n if (!signal) {\n const ctrl = new AbortController;\n signal = ctrl.signal;\n job.must(() => { abortSignals.set(job, null); ctrl.abort(); });\n abortSignals.set(job, signal);\n if (job.result()) ctrl.abort();\n }\n return signal;\n}\n\n/**\n * Wrap a function in a {@link Job} that restarts each time the resulting\n * function is called, thereby canceling any nested jobs and cleaning up any\n * resources used by previous calls. (This can be useful for such things as\n * canceling an in-progress search when the user types more text in a field.)\n *\n * The restarting job will be ended when the job that invoked `restarting()`\n * is finished, canceled, or restarted. Calling the wrapped function after its\n * job has ended will result in an error. You can wrap any function any number\n * of times: each call to `restarting()` creates a new, distinct \"restarting\n * job\" and function wrapper to go with it.\n *\n * @param task (Optional) The function to be wrapped. This can be any function:\n * the returned wrapper function will match its call signature exactly, including\n * overloads. (So for example you could wrap the {@link start} API via\n * `restarting(start)`, to create a function you can pass job-start functions to.\n * When called, the function would cancel any outstanding job from a previous\n * call, and start the new one in its place.)\n *\n * @returns A function of identical type to the input function. If no input\n * function was given, the returned function will just take one argument (a\n * zero-argument function optionally returning a {@link CleanupFn}).\n *\n * @category Jobs\n */\nexport function restarting<F extends AnyFunction>(task: F): F\nexport function restarting(): (task: () => OptionalCleanup) => void\nexport function restarting<F extends AnyFunction>(task?: F): F {\n const outer = getJob(), inner = makeJob<never>(outer), {end} = inner;\n task ||= <F>((f: () => OptionalCleanup) => { inner.must(f()); });\n inner.asyncCatch(e => outer.asyncThrow(e));\n return <F>function(this: ThisParameterType<F>) {\n inner.restart().must(outer.release(end));\n const old = swapCtx(makeCtx(inner));\n try { return apply(task, this, arguments); }\n catch(e) { inner.restart(); throw e; }\n finally { freeCtx(swapCtx(old)); }\n };\n}\n\n/**\n * Wrap an argument-taking function so it will run in (and returns) a new Job\n * when called.\n *\n * This lets you avoid the common pattern of needing to write your functions or\n * methods like this:\n *\n * ```ts\n * function outer(arg1, arg2) {\n * return start(function*() {\n * // ...\n * })\n * }\n * ```\n * and instead write them like this:\n * ```ts\n * const outer = task(function *(arg1, arg2) {\n * // ...\n * });\n * ```\n * or this:\n * ```ts\n * class Something {\n * ⁣⁣@task // auto-detects TC39 or legacy decorators\n * *someMethod(arg1): Yielding<SomeResultType> {\n * // ...\n * }\n * }\n * ```\n *\n * Important: if the wrapped function or method has overloads, the resulting\n * function type will be based on the **last** overload, because TypeScript (at\n * least as of 5.x) is still not very good at dealing with higher order\n * generics, especially if overloads are involved.\n *\n * Also note that TypeScript doesn't allow decorators to change the calling\n * signature or return type of a method, so even though the above method will\n * return a {@link Job}, TypeScript will only see it as a {@link Yielding}.\n *\n * This is fine if all you're going to do is `yield *` it to wait for the\n * result, but if you need to use any job-specific methods on it, you'll have to\n * pass it through {@link start} to have TypeScript treat it as an actual job.\n * (Luckily, start() has a fast path to return the original job if it's passed a\n * job, so you won't actually create a new job by doing this.)\n *\n * @param fn The function to wrap. A function returning a generator or\n * promise-like object (i.e., a {@link StartObj}).\n *\n * @returns A wrapped version of the function that passes through its arguments\n * to the original function, while running it in a new job. (The wrapper also\n * returns the job.)\n *\n * @category Jobs\n */\nexport function task<T, A extends any[], C>(fn: (this: C, ...args: A) => StartObj<T>): (this: C, ...args: A) => Job<T>;\n\n/** @hidden TC39 Decorator protocol */\nexport function task<T, A extends any[], C>(\n fn: (this: C, ...args: A) => StartObj<T>, ctx: {kind: \"method\"}\n): (this: C, ...args: A) => Job<T>;\n\n/** @hidden Legacy Decorator protocol */\nexport function task<T, A extends any[], C, D extends {value?: (this:C, ...args: A) => StartObj<T>}>(\n clsOrProto: any, name: string|symbol, desc: D\n): D\n\nexport function task<T, A extends any[], C, D extends {value?: (this:C, ...args: A) => StartObj<T>}>(\n fn: (this: C, ...args: A) => StartObj<T>, _ctx?: any, desc?: D\n): D | ((this: C, ...args: A) => Job<T>) {\n if (desc) return {...desc, value: task(desc.value)};\n return function (this: C, ...args: A) {\n return start<T>(fn.bind(this, ...args as any[]));\n }\n}\n","import { Job, Yielding } from \"./types.ts\";\nimport { start } from \"./jobutils.ts\";\nimport { isValue, isError, markHandled } from \"./results.ts\";\nimport { isFunction } from \"./utils.ts\";\nimport { connect, Source } from \"./streams.ts\";\n\nexport function callOrWait<T>(\n source: any, method: string, handler: (job: Job<T>, val: T) => void, noArgs: (f?: any) => Yielding<T> | void\n) {\n if (source && isFunction(source[method])) return source[method]() as Yielding<T>;\n if (isFunction(source)) return (\n source.length === 0 ? noArgs(source) : false\n ) || start<T>(job => {\n connect(source as Source<T>, v => handler(job, v)).do(r => {\n if (isValue(r)) job.throw(new Error(\"Stream ended\"));\n else if (isError(r)) job.throw(markHandled(r));\n });\n });\n mustBeSourceOrSignal();\n}\n\nexport function mustBeSourceOrSignal() { throw new TypeError(\"not a source or signal\"); }\n"],"names":[],"mappings":";;AAAO,SAAS,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE;AACtC,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACvB,CAAC;AACM,SAAS,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE;AACxC,EAAE,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC;AACnC,CAAC;AACM,SAAS,QAAQ,CAAC,OAAO,EAAE;AAClC,EAAE,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CA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