feat(build): modernize package configuration, tooling, and tests for ESM-compatible releases
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartdelay',
|
||||
version: '3.0.5',
|
||||
description: 'timeouts for the async/await era, written in TypeScript'
|
||||
version: '3.1.0',
|
||||
description: 'A TypeScript library providing enhanced timeout functions compatible with async/await patterns.'
|
||||
}
|
||||
|
||||
+9
-6
@@ -5,12 +5,12 @@ import * as smartpromise from '@push.rocks/smartpromise';
|
||||
* @param timeInMillisecondArg
|
||||
* @param passOnArg
|
||||
*/
|
||||
export let delayFor = async <T>(
|
||||
export const delayFor = async <T>(
|
||||
timeInMillisecondArg: number,
|
||||
passOnArg?: T,
|
||||
unrefedArg = false
|
||||
) => {
|
||||
const timeout = new Timeout(timeInMillisecondArg, null, unrefedArg);
|
||||
const timeout = new Timeout<null>(timeInMillisecondArg, null, unrefedArg);
|
||||
await timeout.promise;
|
||||
return passOnArg;
|
||||
};
|
||||
@@ -18,7 +18,7 @@ export let delayFor = async <T>(
|
||||
/**
|
||||
* delay for a random time
|
||||
*/
|
||||
export let delayForRandom = async <T>(
|
||||
export const delayForRandom = async <T>(
|
||||
timeMinInMillisecondArg: number,
|
||||
timeMaxInMillisecondArg: number,
|
||||
passOnArg?: T,
|
||||
@@ -35,13 +35,13 @@ export let delayForRandom = async <T>(
|
||||
export class Timeout<T> {
|
||||
promise: Promise<T>;
|
||||
private _deferred: smartpromise.Deferred<T>;
|
||||
private _timeout;
|
||||
private _timeout: ReturnType<typeof setTimeout>;
|
||||
private _cancelled: boolean = false;
|
||||
|
||||
private timeoutInMillis: number;
|
||||
private started: number;
|
||||
|
||||
constructor(timeInMillisecondArg, passOn?: T, unrefedArg = false) {
|
||||
constructor(timeInMillisecondArg: number, passOn?: T, unrefedArg = false) {
|
||||
this.timeoutInMillis = timeInMillisecondArg;
|
||||
this._deferred = smartpromise.defer<T>();
|
||||
this.promise = this._deferred.promise;
|
||||
@@ -60,7 +60,10 @@ export class Timeout<T> {
|
||||
* unreffing a timeout causes the node process to not wait for completion before exit
|
||||
*/
|
||||
public makeUnrefed() {
|
||||
this._timeout.unref();
|
||||
const timeoutWithUnref = this._timeout as ReturnType<typeof setTimeout> & {
|
||||
unref?: () => void;
|
||||
};
|
||||
timeoutWithUnref.unref?.();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user