@dxos/async 0.8.4-main.7ace549 → 0.8.4-main.937b3ca
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/index.mjs +73 -0
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +73 -0
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/cleanup.d.ts +1 -0
- package/dist/types/src/cleanup.d.ts.map +1 -1
- package/dist/types/src/persistent-lifecycle.d.ts +2 -2
- package/dist/types/src/persistent-lifecycle.d.ts.map +1 -1
- package/dist/types/src/task-scheduling.d.ts +28 -0
- package/dist/types/src/task-scheduling.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -7
- package/src/cleanup.ts +1 -0
- package/src/persistent-lifecycle.ts +2 -2
- package/src/task-scheduling.ts +93 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/callback.ts":{"bytes":1595,"imports":[],"format":"esm"},"src/chain.ts":{"bytes":1619,"imports":[],"format":"esm"},"src/cleanup.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/callback.ts":{"bytes":1595,"imports":[],"format":"esm"},"src/chain.ts":{"bytes":1619,"imports":[],"format":"esm"},"src/cleanup.ts":{"bytes":6635,"imports":[{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/debounce.ts":{"bytes":8209,"imports":[],"format":"esm"},"src/errors.ts":{"bytes":2911,"imports":[],"format":"esm"},"src/timeout.ts":{"bytes":8042,"imports":[{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"src/callback.ts","kind":"import-statement","original":"./callback"},{"path":"src/errors.ts","kind":"import-statement","original":"./errors"}],"format":"esm"},"src/event-emitter.ts":{"bytes":4155,"imports":[{"path":"src/timeout.ts","kind":"import-statement","original":"./timeout"}],"format":"esm"},"src/events.ts":{"bytes":39464,"imports":[{"path":"@dxos/context","kind":"import-statement","external":true}],"format":"esm"},"src/mutex.ts":{"bytes":12647,"imports":[{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true}],"format":"esm"},"src/trigger.ts":{"bytes":14052,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"src/errors.ts","kind":"import-statement","original":"./errors"},{"path":"src/timeout.ts","kind":"import-statement","original":"./timeout"}],"format":"esm"},"src/observable.ts":{"bytes":17824,"imports":[{"path":"zen-observable","kind":"import-statement","external":true},{"path":"zen-push","kind":"import-statement","external":true},{"path":"src/trigger.ts","kind":"import-statement","original":"./trigger"}],"format":"esm"},"src/observable-value.ts":{"bytes":6436,"imports":[{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/track-leaks.ts":{"bytes":8414,"imports":[{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/task-scheduling.ts":{"bytes":23288,"imports":[{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"src/track-leaks.ts","kind":"import-statement","original":"./track-leaks"},{"path":"src/trigger.ts","kind":"import-statement","original":"./trigger"}],"format":"esm"},"src/persistent-lifecycle.ts":{"bytes":12773,"imports":[{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"src/mutex.ts","kind":"import-statement","original":"./mutex"},{"path":"src/task-scheduling.ts","kind":"import-statement","original":"./task-scheduling"},{"path":"src/timeout.ts","kind":"import-statement","original":"./timeout"}],"format":"esm"},"src/push-iterable.ts":{"bytes":5922,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"src/trigger.ts","kind":"import-statement","original":"./trigger"}],"format":"esm"},"src/stream-to-array.ts":{"bytes":4935,"imports":[],"format":"esm"},"src/test-stream.ts":{"bytes":5038,"imports":[{"path":"@dxos/node-std/stream","kind":"import-statement","external":true},{"path":"src/events.ts","kind":"import-statement","original":"./events"},{"path":"src/timeout.ts","kind":"import-statement","original":"./timeout"}],"format":"esm"},"src/testing.ts":{"bytes":8388,"imports":[{"path":"src/timeout.ts","kind":"import-statement","original":"./timeout"},{"path":"src/trigger.ts","kind":"import-statement","original":"./trigger"}],"format":"esm"},"src/timer.ts":{"bytes":5879,"imports":[{"path":"src/events.ts","kind":"import-statement","original":"./events"}],"format":"esm"},"src/update-scheduler.ts":{"bytes":9706,"imports":[{"path":"src/task-scheduling.ts","kind":"import-statement","original":"./task-scheduling"}],"format":"esm"},"src/index.ts":{"bytes":2335,"imports":[{"path":"src/callback.ts","kind":"import-statement","original":"./callback"},{"path":"src/chain.ts","kind":"import-statement","original":"./chain"},{"path":"src/cleanup.ts","kind":"import-statement","original":"./cleanup"},{"path":"src/debounce.ts","kind":"import-statement","original":"./debounce"},{"path":"src/errors.ts","kind":"import-statement","original":"./errors"},{"path":"src/event-emitter.ts","kind":"import-statement","original":"./event-emitter"},{"path":"src/events.ts","kind":"import-statement","original":"./events"},{"path":"src/mutex.ts","kind":"import-statement","original":"./mutex"},{"path":"src/observable.ts","kind":"import-statement","original":"./observable"},{"path":"src/observable-value.ts","kind":"import-statement","original":"./observable-value"},{"path":"src/persistent-lifecycle.ts","kind":"import-statement","original":"./persistent-lifecycle"},{"path":"src/push-iterable.ts","kind":"import-statement","original":"./push-iterable"},{"path":"src/stream-to-array.ts","kind":"import-statement","original":"./stream-to-array"},{"path":"src/task-scheduling.ts","kind":"import-statement","original":"./task-scheduling"},{"path":"src/test-stream.ts","kind":"import-statement","original":"./test-stream"},{"path":"src/testing.ts","kind":"import-statement","original":"./testing"},{"path":"src/timeout.ts","kind":"import-statement","original":"./timeout"},{"path":"src/timer.ts","kind":"import-statement","original":"./timer"},{"path":"src/track-leaks.ts","kind":"import-statement","original":"./track-leaks"},{"path":"src/trigger.ts","kind":"import-statement","original":"./trigger"},{"path":"src/update-scheduler.ts","kind":"import-statement","original":"./update-scheduler"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":103799},"dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"zen-observable","kind":"import-statement","external":true},{"path":"zen-push","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/node-std/stream","kind":"import-statement","external":true}],"exports":["AsyncTask","CancellableObservableProvider","DeferredTask","Event","MulticastObservable","Mutex","MutexGuard","Observable","ObservableProvider","PersistentLifecycle","PushStream","SubscriptionList","SubscriptionSet","TestStream","TimeoutError","Timer","Trigger","TriggerState","UpdateScheduler","addEventListener","addListener","asyncReturn","asyncTimeout","chain","combine","debounce","debounceAndThrottle","delay","dumpLeaks","interval","latch","makePushIterable","observableError","onEvent","promiseFromCallback","runInContext","runInContextAsync","scheduleExponentialBackoffTaskInterval","scheduleMicroTask","scheduleTask","scheduleTaskInterval","sleep","sleepWithContext","streamToArray","synchronized","throttle","timeout","toError","trackLeaks","trackResource","trigger","unrefTimeout","until","untilError","untilPromise","waitForCondition","waitForEvent"],"entryPoint":"src/index.ts","inputs":{"src/callback.ts":{"bytesInOutput":185},"src/index.ts":{"bytesInOutput":0},"src/chain.ts":{"bytesInOutput":216},"src/cleanup.ts":{"bytesInOutput":1045},"src/debounce.ts":{"bytesInOutput":1032},"src/errors.ts":{"bytesInOutput":476},"src/timeout.ts":{"bytesInOutput":1486},"src/event-emitter.ts":{"bytesInOutput":697},"src/events.ts":{"bytesInOutput":8703},"src/mutex.ts":{"bytesInOutput":2413},"src/observable.ts":{"bytesInOutput":3691},"src/trigger.ts":{"bytesInOutput":3014},"src/observable-value.ts":{"bytesInOutput":951},"src/persistent-lifecycle.ts":{"bytesInOutput":3536},"src/task-scheduling.ts":{"bytesInOutput":4915},"src/track-leaks.ts":{"bytesInOutput":2136},"src/push-iterable.ts":{"bytesInOutput":1389},"src/stream-to-array.ts":{"bytesInOutput":967},"src/test-stream.ts":{"bytesInOutput":915},"src/testing.ts":{"bytesInOutput":1419},"src/timer.ts":{"bytesInOutput":1065},"src/update-scheduler.ts":{"bytesInOutput":1952}},"bytes":43712}}}
|
|
@@ -1074,6 +1074,78 @@ var DeferredTask = class {
|
|
|
1074
1074
|
await this._currentTask;
|
|
1075
1075
|
}
|
|
1076
1076
|
};
|
|
1077
|
+
var AsyncTask = class {
|
|
1078
|
+
#callback;
|
|
1079
|
+
#ctx = void 0;
|
|
1080
|
+
#scheduled = false;
|
|
1081
|
+
#currentTask = null;
|
|
1082
|
+
#nextTask = new Trigger();
|
|
1083
|
+
constructor(callback) {
|
|
1084
|
+
this.#callback = callback;
|
|
1085
|
+
}
|
|
1086
|
+
get scheduled() {
|
|
1087
|
+
return this.#scheduled;
|
|
1088
|
+
}
|
|
1089
|
+
/**
|
|
1090
|
+
* Context of the resource that owns the task.
|
|
1091
|
+
* When the context is disposed, the task is cancelled and cannot be scheduled again.
|
|
1092
|
+
*/
|
|
1093
|
+
// TODO(dmaretskyi): We don't really need to pass ctx in here, since close will also signal dispose.
|
|
1094
|
+
open(ctx) {
|
|
1095
|
+
this.#ctx = ctx;
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1098
|
+
* Closes the task and waits for it to finish if it is running.
|
|
1099
|
+
*/
|
|
1100
|
+
async close() {
|
|
1101
|
+
this.#ctx = void 0;
|
|
1102
|
+
await this.join();
|
|
1103
|
+
}
|
|
1104
|
+
[Symbol.asyncDispose]() {
|
|
1105
|
+
return this.close();
|
|
1106
|
+
}
|
|
1107
|
+
/**
|
|
1108
|
+
* Schedule the task to run asynchronously.
|
|
1109
|
+
*/
|
|
1110
|
+
schedule() {
|
|
1111
|
+
if (!this.#ctx || this.#ctx.disposed) {
|
|
1112
|
+
throw new Error("AsyncTask not open");
|
|
1113
|
+
}
|
|
1114
|
+
if (this.#scheduled) {
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
1117
|
+
scheduleTask(this.#ctx, async () => {
|
|
1118
|
+
await this.#currentTask;
|
|
1119
|
+
if (!this.#ctx || this.#ctx.disposed) {
|
|
1120
|
+
return;
|
|
1121
|
+
}
|
|
1122
|
+
this.#scheduled = false;
|
|
1123
|
+
const completionTrigger = this.#nextTask;
|
|
1124
|
+
this.#nextTask = new Trigger();
|
|
1125
|
+
this.#currentTask = runInContextAsync(this.#ctx, () => this.#callback()).then(() => {
|
|
1126
|
+
completionTrigger.wake();
|
|
1127
|
+
});
|
|
1128
|
+
});
|
|
1129
|
+
this.#scheduled = true;
|
|
1130
|
+
}
|
|
1131
|
+
/**
|
|
1132
|
+
* Schedule the task to run and wait for it to finish.
|
|
1133
|
+
*/
|
|
1134
|
+
async runBlocking() {
|
|
1135
|
+
if (this.#ctx?.disposed) {
|
|
1136
|
+
throw new ContextDisposedError2();
|
|
1137
|
+
}
|
|
1138
|
+
this.schedule();
|
|
1139
|
+
await this.#nextTask.wait();
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* Waits for the current task to finish if it is running.
|
|
1143
|
+
* Does not schedule a new task.
|
|
1144
|
+
*/
|
|
1145
|
+
async join() {
|
|
1146
|
+
await this.#currentTask;
|
|
1147
|
+
}
|
|
1148
|
+
};
|
|
1077
1149
|
var runInContext = (ctx, fn) => {
|
|
1078
1150
|
try {
|
|
1079
1151
|
fn();
|
|
@@ -1596,6 +1668,7 @@ var UpdateScheduler = class {
|
|
|
1596
1668
|
}
|
|
1597
1669
|
};
|
|
1598
1670
|
export {
|
|
1671
|
+
AsyncTask,
|
|
1599
1672
|
CancellableObservableProvider,
|
|
1600
1673
|
DeferredTask,
|
|
1601
1674
|
Event,
|