@syncot/util
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -91,9 +91,9 @@ /// <reference types="node" /> | ||
*/ | ||
emitAsync<K extends keyof Events>(name: K, ...args: Args<Events[K]>): Promise<boolean>; | ||
emitAsync(name: symbol, ...args: any[]): Promise<boolean>; | ||
emitAsync<K extends keyof Events>(name: K, ...args: Args<Events[K]>): void; | ||
emitAsync(name: symbol, ...args: any[]): void; | ||
/** | ||
* Just like `emitAsync` but dispatches the event even if the emitter has been destroyed. | ||
*/ | ||
emitAsyncForce<K extends keyof Events>(name: K, ...args: Args<Events[K]>): Promise<boolean>; | ||
emitAsyncForce(name: symbol, ...args: any[]): Promise<boolean>; | ||
emitAsyncForce<K extends keyof Events>(name: K, ...args: Args<Events[K]>): void; | ||
emitAsyncForce(name: symbol, ...args: any[]): void; | ||
/** | ||
@@ -100,0 +100,0 @@ * Destroys this event emitter and emits a destroy event asynchronously. |
@@ -54,9 +54,7 @@ import { strict as assert } from 'assert'; | ||
} | ||
async emitAsync(name, ...args) { | ||
await Promise.resolve(); | ||
return this.emit(name, ...args); | ||
emitAsync(name, ...args) { | ||
process.nextTick(() => this.emit(name, ...args)); | ||
} | ||
async emitAsyncForce(name, ...args) { | ||
await Promise.resolve(); | ||
return this.emitForce(name, ...args); | ||
emitAsyncForce(name, ...args) { | ||
process.nextTick(() => this.emitForce(name, ...args)); | ||
} | ||
@@ -63,0 +61,0 @@ /** |
export declare function noop(): void; | ||
/** | ||
* Returns a Promise that resolves on `process.nextTick`. | ||
*/ | ||
export declare function whenNextTick(): Promise<{}>; | ||
/** | ||
* Returns a Promise that resolves after the specified minimum number of milliseconds. | ||
*/ | ||
export declare function delay(minDelayMilliseconds?: number): Promise<{}>; |
@@ -1,2 +0,15 @@ | ||
// tslint:disable-next-line:no-empty | ||
export function noop() { } | ||
export function noop() { | ||
// Do nothing. | ||
} | ||
/** | ||
* Returns a Promise that resolves on `process.nextTick`. | ||
*/ | ||
export function whenNextTick() { | ||
return new Promise(resolve => process.nextTick(resolve)); | ||
} | ||
/** | ||
* Returns a Promise that resolves after the specified minimum number of milliseconds. | ||
*/ | ||
export function delay(minDelayMilliseconds = 0) { | ||
return new Promise(resolve => setTimeout(resolve, minDelayMilliseconds)); | ||
} |
{ | ||
"name": "@syncot/util", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "A collection of utilities required by other @syncot modules.", | ||
@@ -33,3 +33,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "5fd7d4343e2c3c6e047f338feabea25d672444c3" | ||
"gitHead": "6049a02006707c0623e91fb0f145fe4a8e1c80cc" | ||
} |
19558
478