Socket
Socket
Sign inDemoInstall

@dxos/async

Package Overview
Dependencies
Maintainers
23
Versions
2980
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dxos/async - npm Package Compare versions

Comparing version 2.17.2 to 2.17.3

6

dist/src/async.js

@@ -92,3 +92,3 @@ "use strict";

const stopTime = timeout ? Date.now() + timeout : 0;
const [provider, resolver] = trigger_1.trigger();
const [provider, resolver] = (0, trigger_1.trigger)();
const waiter = async () => {

@@ -109,9 +109,9 @@ // eslint-disable-next-line no-unmodified-loop-condition

// eslint-disable-next-line no-await-in-loop
await exports.sleep(interval);
await (0, exports.sleep)(interval);
}
};
setTimeout(waiter, 0);
return timeout ? exports.promiseTimeout(provider(), timeout) : provider();
return timeout ? (0, exports.promiseTimeout)(provider(), timeout) : provider();
};
exports.waitForCondition = waitForCondition;
//# sourceMappingURL=async.js.map

@@ -12,7 +12,7 @@ "use strict";

const now = Date.now();
await async_1.sleep(100);
await (0, async_1.sleep)(100);
expect(Date.now()).toBeGreaterThanOrEqual(now + 100);
});
test('trigger', async () => {
const [value, setValue] = trigger_1.trigger();
const [value, setValue] = (0, trigger_1.trigger)();
const t = setTimeout(() => setValue('test'), 10);

@@ -25,9 +25,9 @@ const result = await value();

{
const promise = async_1.timeout(() => 'test', 100);
const value = await async_1.promiseTimeout(promise, 200);
const promise = (0, async_1.timeout)(() => 'test', 100);
const value = await (0, async_1.promiseTimeout)(promise, 200);
expect(value).toBe('test');
}
{
const promise = async_1.timeout(() => 'test', 200);
await debug_1.expectToThrow(() => async_1.promiseTimeout(promise, 100));
const promise = (0, async_1.timeout)(() => 'test', 200);
await (0, debug_1.expectToThrow)(() => (0, async_1.promiseTimeout)(promise, 100));
}

@@ -38,3 +38,3 @@ });

const stop = Date.now() + 100;
const value = await async_1.waitForCondition(() => Date.now() > stop, 200);
const value = await (0, async_1.waitForCondition)(() => Date.now() > stop, 200);
expect(value).toBe(true);

@@ -45,5 +45,5 @@ expect(Date.now()).toBeGreaterThanOrEqual(stop);

const stop = Date.now() + 200;
await debug_1.expectToThrow(() => async_1.waitForCondition(() => Date.now() > stop, 100));
await (0, debug_1.expectToThrow)(() => (0, async_1.waitForCondition)(() => Date.now() > stop, 100));
}
});
//# sourceMappingURL=async.test.js.map

@@ -123,2 +123,8 @@ export declare type Effect = () => (() => void) | undefined;

discardParameter(): Event<void>;
/**
* Overriden to not retun implementation details.
*/
toJSON(): {
listenerCount: number;
};
private _trigger;

@@ -125,0 +131,0 @@ private _runEffects;

@@ -218,2 +218,10 @@ "use strict";

}
/**
* Overriden to not retun implementation details.
*/
toJSON() {
return {
listenerCount: this.listenerCount()
};
}
async _trigger(listener, data) {

@@ -220,0 +228,0 @@ await waitImmediate(); // Acts like setImmediate but preserves the stack-trace.

@@ -25,3 +25,3 @@ "use strict";

event.emit(true);
await async_1.sleep(100);
await (0, async_1.sleep)(100);
expect(pureCount).toBe(3);

@@ -28,0 +28,0 @@ expect(debounceCount).toBe(0);

@@ -1,6 +0,6 @@

export function onEvent(eventEmitter: any, eventName: string, callback: Function): () => any;
export function onEvent(eventEmitter: EventEmitter, eventName: string, callback: Function): () => any;
export function addListener(eventEmitter: any, eventName: any, callback: any): {
remove: () => any;
};
export function waitForEvent(eventEmitter: any, eventName: string, test?: Function | undefined, timeout?: number | undefined, error?: unknown): Promise<unknown>;
export function waitForEvent(eventEmitter: EventEmitter, eventName: string, test?: Function | undefined, timeout?: number | undefined, error?: unknown): Promise<unknown>;
//# sourceMappingURL=events.d.ts.map

@@ -23,3 +23,3 @@ "use strict";

const addListener = (eventEmitter, eventName, callback) => {
const off = exports.onEvent(eventEmitter, eventName, callback);
const off = (0, exports.onEvent)(eventEmitter, eventName, callback);
return {

@@ -42,3 +42,3 @@ remove: () => off()

const promise = new Promise((resolve) => {
off = exports.onEvent(eventEmitter, eventName, (...args) => {
off = (0, exports.onEvent)(eventEmitter, eventName, (...args) => {
if (!test || test(...args)) {

@@ -49,5 +49,5 @@ resolve(...args);

});
return timeout ? async_1.promiseTimeout(promise, timeout, error).finally(off) : promise.finally(off);
return timeout ? (0, async_1.promiseTimeout)(promise, timeout, error).finally(off) : promise.finally(off);
};
exports.waitForEvent = waitForEvent;
//# sourceMappingURL=events.js.map

@@ -18,4 +18,4 @@ "use strict";

const emitter = new events_1.default();
const [promise, resolve] = latch_1.latch();
const off = events_2.onEvent(emitter, 'test', () => {
const [promise, resolve] = (0, latch_1.latch)();
const off = (0, events_2.onEvent)(emitter, 'test', () => {
off();

@@ -30,3 +30,3 @@ expect(emitter.listenerCount('test')).toBe(0);

const emitter = new events_1.default();
const waiting = events_2.waitForEvent(emitter, 'test');
const waiting = (0, events_2.waitForEvent)(emitter, 'test');
setTimeout(() => emitter.emit('test', { value: 500 }), 10);

@@ -39,7 +39,7 @@ const { value } = await waiting;

const emitter = new events_1.default();
const waiting = events_2.waitForEvent(emitter, 'test', value => (value === 300) && value);
const waiting = (0, events_2.waitForEvent)(emitter, 'test', value => (value === 300) && value);
setTimeout(() => emitter.emit('test', 100), 10);
setTimeout(() => emitter.emit('test', 200), 20);
setTimeout(() => emitter.emit('test', 300), 30);
const value = await async_1.promiseTimeout(waiting, 100);
const value = await (0, async_1.promiseTimeout)(waiting, 100);
expect(value).toBe(300);

@@ -50,5 +50,5 @@ expect(emitter.listenerCount('test')).toBe(0);

const emitter = new events_1.default();
await debug_1.expectToThrow(() => events_2.waitForEvent(emitter, 'test', null, 100));
await (0, debug_1.expectToThrow)(() => (0, events_2.waitForEvent)(emitter, 'test', null, 100));
expect(emitter.listenerCount('test')).toBe(0);
});
//# sourceMappingURL=events.test.js.map

@@ -16,3 +16,3 @@ "use strict";

const latch = (n = 1) => {
assert_1.default(n > 0);
(0, assert_1.default)(n > 0);
let callback;

@@ -19,0 +19,0 @@ const promise = new Promise((resolve) => {

@@ -36,3 +36,3 @@ "use strict";

// Immediately update the promise before invoking any async actions so that next invocation waits for our task to complete.
const [getPromise, resolve] = trigger_1.trigger();
const [getPromise, resolve] = (0, trigger_1.trigger)();
this._lastPromise = getPromise();

@@ -39,0 +39,0 @@ await prevPromise;

@@ -38,3 +38,3 @@ "use strict";

events.push('lock1');
await async_1.sleep(10);
await (0, async_1.sleep)(10);
events.push('lock2');

@@ -71,3 +71,3 @@ }).then(() => {

});
await async_1.sleep(10);
await (0, async_1.sleep)(10);
expect(resolved).toEqual(false);

@@ -124,3 +124,3 @@ });

this.events.push('foo start');
await async_1.sleep(10);
await (0, async_1.sleep)(10);
this.events.push('foo end');

@@ -130,3 +130,3 @@ }

this.events.push('bar start');
await async_1.sleep(30);
await (0, async_1.sleep)(30);
this.events.push('bar end');

@@ -133,0 +133,0 @@ }

@@ -12,3 +12,3 @@ "use strict";

const sink = (emitter, event, count = 1) => {
const [getPromise, resolve] = trigger_1.trigger();
const [getPromise, resolve] = (0, trigger_1.trigger)();
let counter = 0;

@@ -15,0 +15,0 @@ const listener = () => {

{
"name": "@dxos/async",
"version": "2.17.2",
"version": "2.17.3",
"description": "Async utils.",

@@ -27,3 +27,3 @@ "bugs": {

"dependencies": {
"@dxos/debug": "2.17.2"
"@dxos/debug": "2.17.3"
},

@@ -30,0 +30,0 @@ "devDependencies": {

@@ -257,2 +257,11 @@ //

/**
* Overriden to not retun implementation details.
*/
toJSON () {
return {
listenerCount: this.listenerCount()
};
}
private async _trigger (listener: (data: T) => void, data: T) {

@@ -259,0 +268,0 @@ await waitImmediate(); // Acts like setImmediate but preserves the stack-trace.

@@ -129,3 +129,3 @@ //

});
} catch (err) {
} catch (err: any) {
error = err;

@@ -132,0 +132,0 @@ throw error;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc