@dxos/async 0.6.12-main.ed7cda7 → 0.6.12-staging.0b4bb48

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/async",
3
- "version": "0.6.12-main.ed7cda7",
3
+ "version": "0.6.12-staging.0b4bb48",
4
4
  "description": "Async utilities.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -10,8 +10,7 @@
10
10
  ".": {
11
11
  "browser": "./dist/lib/browser/index.mjs",
12
12
  "node": {
13
- "require": "./dist/lib/node/index.cjs",
14
- "default": "./dist/lib/node-esm/index.mjs"
13
+ "default": "./dist/lib/node/index.cjs"
15
14
  },
16
15
  "types": "./dist/types/src/index.d.ts"
17
16
  }
@@ -27,12 +26,12 @@
27
26
  "dependencies": {
28
27
  "zen-observable": "^0.10.0",
29
28
  "zen-push": "^0.3.1",
30
- "@dxos/debug": "0.6.12-main.ed7cda7",
31
- "@dxos/context": "0.6.12-main.ed7cda7",
32
- "@dxos/invariant": "0.6.12-main.ed7cda7",
33
- "@dxos/util": "0.6.12-main.ed7cda7",
34
- "@dxos/log": "0.6.12-main.ed7cda7",
35
- "@dxos/node-std": "0.6.12-main.ed7cda7"
29
+ "@dxos/debug": "0.6.12-staging.0b4bb48",
30
+ "@dxos/invariant": "0.6.12-staging.0b4bb48",
31
+ "@dxos/node-std": "0.6.12-staging.0b4bb48",
32
+ "@dxos/util": "0.6.12-staging.0b4bb48",
33
+ "@dxos/log": "0.6.12-staging.0b4bb48",
34
+ "@dxos/context": "0.6.12-staging.0b4bb48"
36
35
  },
37
36
  "devDependencies": {
38
37
  "@types/zen-observable": "^0.8.3"
@@ -2,8 +2,10 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
+ import { expect } from 'chai';
5
6
  import { EventEmitter } from 'node:events';
6
- import { describe, expect, test } from 'vitest';
7
+
8
+ import { describe, test } from '@dxos/test';
7
9
 
8
10
  import { onEvent, waitForEvent } from './event-emitter';
9
11
  import { latch } from './latch';
@@ -2,11 +2,12 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- // import { setFlagsFromString } from 'node:v8';
6
- // import { runInNewContext } from 'node:vm';
7
- import { describe, expect, test } from 'vitest';
5
+ import { expect } from 'chai';
6
+ import { setFlagsFromString } from 'node:v8';
7
+ import { runInNewContext } from 'node:vm';
8
8
 
9
9
  import { Context } from '@dxos/context';
10
+ import { describe, test } from '@dxos/test';
10
11
 
11
12
  import { Event } from './events';
12
13
  import { sleep } from './timeout';
@@ -89,28 +90,28 @@ describe('Event', () => {
89
90
  expect(error.message).to.equal('test');
90
91
  });
91
92
 
92
- // test.skip('weak', async () => {
93
- // setFlagsFromString('--expose_gc');
94
- // const gc = runInNewContext('gc'); // nocommit
93
+ test.skip('weak', async () => {
94
+ setFlagsFromString('--expose_gc');
95
+ const gc = runInNewContext('gc'); // nocommit
95
96
 
96
- // let called = 0;
97
- // let callback: (() => void) | null = () => {
98
- // called++;
99
- // };
97
+ let called = 0;
98
+ let callback: (() => void) | null = () => {
99
+ called++;
100
+ };
100
101
 
101
- // const event = new Event();
102
- // event.on(new Context(), callback, { weak: true });
102
+ const event = new Event();
103
+ event.on(new Context(), callback, { weak: true });
103
104
 
104
- // event.emit();
105
- // expect(called).to.equal(1);
105
+ event.emit();
106
+ expect(called).to.equal(1);
106
107
 
107
- // callback = null;
108
- // while (event.listenerCount() > 0) {
109
- // gc();
110
- // await sleep(5);
111
- // }
108
+ callback = null;
109
+ while (event.listenerCount() > 0) {
110
+ gc();
111
+ await sleep(5);
112
+ }
112
113
 
113
- // event.emit();
114
- // expect(called).to.equal(1);
115
- // });
114
+ event.emit();
115
+ expect(called).to.equal(1);
116
+ });
116
117
  });
package/src/events.ts CHANGED
@@ -73,9 +73,6 @@ export type ListenerOptions = {
73
73
  */
74
74
  // TODO(burdon): Rename EventSink? (Event is a built-in type).
75
75
  export class Event<T = void> implements ReadOnlyEvent<T> {
76
- /**
77
- * Propagate events to parent.
78
- */
79
76
  static wrap<T>(emitter: EventEmitterLike, eventName: string): Event<T> {
80
77
  const event = new Event<T>();
81
78
 
@@ -346,15 +343,13 @@ export class Event<T = void> implements ReadOnlyEvent<T> {
346
343
  */
347
344
  export interface ReadOnlyEvent<T = void> {
348
345
  /**
349
- * Register an event listener.
346
+ * Registers an event listener.
350
347
  * If provided callback was already registered as once-listener, it is made permanent.
351
348
  *
352
349
  * @param callback
353
- * @param options.weak If true, the callback will be weakly referenced and will be garbage collected if no other references to it exist.
354
350
  * @returns function that unsubscribes this event listener
355
351
  */
356
352
  on(callback: (data: T) => void): UnsubscribeCallback;
357
- on(ctx: Context, callback: (data: T) => void, options?: ListenerOptions): UnsubscribeCallback;
358
353
 
359
354
  /**
360
355
  * Unsubscribes this callback from new events. Includes persistent and once-listeners.
@@ -397,14 +392,6 @@ export interface ReadOnlyEvent<T = void> {
397
392
  * Turn any variant of `Event<T>` into an `Event<void>` discarding the callback parameter.
398
393
  */
399
394
  discardParameter(): Event<void>;
400
-
401
- /**
402
- * Triggers an event with at least `timeout` milliseconds between each event.
403
- * If the event is triggered more often, the event is delayed until the timeout is reached.
404
- * If event is emitted for the first time or event wasn't fired for `timeout` milliseconds,
405
- * the event is emitted after `timeout / 8` ms.
406
- */
407
- debounce(timeout?: number): Event<void>;
408
395
  }
409
396
 
410
397
  class EventListener<T> {
package/src/mutex.test.ts CHANGED
@@ -2,9 +2,10 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import { describe, expect, test } from 'vitest';
5
+ import { expect } from 'chai';
6
6
 
7
7
  import { expectToThrow } from '@dxos/debug';
8
+ import { describe, test } from '@dxos/test';
8
9
 
9
10
  import { Mutex, synchronized } from './mutex';
10
11
  import { sleep } from './timeout';
@@ -138,7 +139,7 @@ describe('Mutex', () => {
138
139
 
139
140
  expect(error!.stack!.includes('throwsError')).to.be.true;
140
141
  expect(error!.stack!.includes('callmutex')).to.be.true;
141
- }); // .skipEnvironments('webkit');
142
+ }).skipEnvironments('webkit');
142
143
 
143
144
  test('works with explicit resource management syntax', async () => {
144
145
  const mutex = new Mutex();
@@ -2,7 +2,9 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import { describe, expect, test } from 'vitest';
5
+ import { expect } from 'chai';
6
+
7
+ import { describe, test } from '@dxos/test';
6
8
 
7
9
  import { type AsyncEvents, TimeoutError } from './errors';
8
10
  import { latch } from './latch';
@@ -2,7 +2,9 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { describe, expect, onTestFinished, test } from 'vitest';
5
+ import { expect } from 'chai';
6
+
7
+ import { afterTest, describe, test } from '@dxos/test';
6
8
 
7
9
  import { Event } from './events';
8
10
  import { MulticastObservable, Observable, PushStream } from './observable';
@@ -21,7 +23,7 @@ describe('multicast observable', () => {
21
23
  expect(value).to.equal(1);
22
24
  trigger.wake();
23
25
  });
24
- onTestFinished(() => subscription.unsubscribe());
26
+ afterTest(() => subscription.unsubscribe());
25
27
  await trigger.wait();
26
28
  });
27
29
 
@@ -44,8 +46,8 @@ describe('multicast observable', () => {
44
46
  }
45
47
  });
46
48
 
47
- onTestFinished(() => subscription1.unsubscribe());
48
- onTestFinished(() => subscription2.unsubscribe());
49
+ afterTest(() => subscription1.unsubscribe());
50
+ afterTest(() => subscription2.unsubscribe());
49
51
 
50
52
  const next = { new: 'value' };
51
53
  event.emit(next);
@@ -98,7 +100,7 @@ describe('multicast observable', () => {
98
100
  const subscription = mapped.subscribe((value) => {
99
101
  result.wake(value);
100
102
  });
101
- onTestFinished(() => subscription.unsubscribe());
103
+ afterTest(() => subscription.unsubscribe());
102
104
  expect(await result.wait()).to.deep.equal(6);
103
105
  });
104
106
 
@@ -119,7 +121,7 @@ describe('multicast observable', () => {
119
121
  const subscription = reduced.subscribe((value) => {
120
122
  result.wake(value);
121
123
  });
122
- onTestFinished(() => subscription.unsubscribe());
124
+ afterTest(() => subscription.unsubscribe());
123
125
  expect(await result.wait()).to.deep.equal(6);
124
126
  });
125
127
 
@@ -2,9 +2,11 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import { describe, expect, test } from 'vitest';
5
+ import { expect } from 'chai';
6
+ import waitForExpect from 'wait-for-expect';
6
7
 
7
8
  import { Context } from '@dxos/context';
9
+ import { describe, test } from '@dxos/test';
8
10
 
9
11
  import { DeferredTask, scheduleTask } from './task-scheduling';
10
12
  import { sleep } from './timeout';
@@ -23,7 +25,9 @@ describe('task-scheduling', () => {
23
25
  throw new Error('test');
24
26
  });
25
27
 
26
- await expect.poll(() => error.message).toBe('test');
28
+ await waitForExpect(() => {
29
+ expect(error.message).to.eq('test');
30
+ });
27
31
  });
28
32
 
29
33
  test('cancelation', async () => {
@@ -2,7 +2,7 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import { test } from 'vitest';
5
+ import { test } from '@dxos/test';
6
6
 
7
7
  import { TestStream } from './test-stream';
8
8
 
@@ -2,9 +2,10 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import { describe, expect, test } from 'vitest';
5
+ import { expect } from 'chai';
6
6
 
7
7
  import { expectToThrow } from '@dxos/debug';
8
+ import { describe, test } from '@dxos/test';
8
9
 
9
10
  import { waitForCondition } from './testing';
10
11
 
@@ -2,7 +2,10 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import { describe, expect, test } from 'vitest';
5
+ import { expect } from 'chai';
6
+
7
+ import { expectToThrow } from '@dxos/debug';
8
+ import { describe, test } from '@dxos/test';
6
9
 
7
10
  import { asyncTimeout, sleep } from './timeout';
8
11
 
@@ -15,7 +18,7 @@ describe('timeout', () => {
15
18
 
16
19
  test('fails', async () => {
17
20
  const promise = sleep(200).then(() => 'test');
18
- await expect(() => asyncTimeout(promise, 100, new Error('timeout'))).rejects.toThrowError();
21
+ await expectToThrow(() => asyncTimeout(promise, 100, new Error('timeout')));
19
22
  });
20
23
 
21
24
  test('sleep', async () => {
@@ -2,11 +2,16 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import { describe, expect, test } from 'vitest';
5
+ import chai, { expect } from 'chai';
6
+ import chaiAsPromised from 'chai-as-promised';
7
+
8
+ import { describe, test } from '@dxos/test';
6
9
 
7
10
  import { sleep } from './timeout';
8
11
  import { Trigger, TriggerState, trigger } from './trigger';
9
12
 
13
+ chai.use(chaiAsPromised);
14
+
10
15
  describe('trigger', () => {
11
16
  test('trigger', async () => {
12
17
  const [value, setValue] = trigger<any>();
@@ -47,7 +52,7 @@ describe('trigger', () => {
47
52
  const error = new Error('Test error');
48
53
  const promise = trigger.wait();
49
54
  trigger.throw(error);
50
- await expect(promise).rejects.toThrowError(error);
55
+ await expect(promise).to.be.rejectedWith(error);
51
56
  expect(trigger.state).to.equal(TriggerState.REJECTED);
52
57
  trigger.reset();
53
58
  expect(trigger.state).to.equal(TriggerState.WAITING);
package/src/until.test.ts CHANGED
@@ -2,7 +2,10 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import { describe, expect, test } from 'vitest';
5
+ import { expect } from 'chai';
6
+
7
+ import { expectToThrow } from '@dxos/debug';
8
+ import { describe, test } from '@dxos/test';
6
9
 
7
10
  import { sleep } from './timeout';
8
11
  import { until } from './until';
@@ -19,29 +22,29 @@ describe('until', () => {
19
22
  });
20
23
 
21
24
  test('error', async () => {
22
- await expect(async () => {
25
+ await expectToThrow(async () => {
23
26
  await until(async (resolve, reject) => {
24
27
  await sleep(100);
25
28
  reject(new Error());
26
29
  });
27
- }).rejects.toThrowError();
30
+ });
28
31
  });
29
32
 
30
33
  test('catch', async () => {
31
- await expect(async () => {
34
+ await expectToThrow(async () => {
32
35
  await until(async () => {
33
36
  await sleep(100);
34
37
  throw new Error();
35
38
  });
36
- }).rejects.toThrowError();
39
+ });
37
40
  });
38
41
 
39
42
  test('timeout', async () => {
40
- await expect(async () => {
43
+ await expectToThrow(async () => {
41
44
  await until(async (resolve) => {
42
45
  await sleep(500);
43
46
  resolve();
44
47
  }, 100); // Timeout before complete.
45
- }).rejects.toThrowError();
48
+ });
46
49
  });
47
50
  });
@@ -2,9 +2,10 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { describe, expect, test } from 'vitest';
5
+ import { expect } from 'chai';
6
6
 
7
7
  import { Context } from '@dxos/context';
8
+ import { describe, test } from '@dxos/test';
8
9
 
9
10
  import { sleep } from './timeout';
10
11
  import { UpdateScheduler } from './update-scheduler';