@xylabs/forget
Advanced tools
Comparing version 2.11.3 to 2.11.4
@@ -1,10 +0,88 @@ | ||
'use strict'; | ||
"use strict"; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var forget = require('./forget.js'); | ||
require('@xylabs/delay'); | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
ForgetPromise: () => ForgetPromise, | ||
forget: () => forget | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
exports.ForgetPromise = forget.ForgetPromise; | ||
exports.forget = forget.forget; | ||
//# sourceMappingURL=index.js.map | ||
// src/forget.ts | ||
var import_delay = require("@xylabs/delay"); | ||
var ForgetPromise = class { | ||
static activeForgets = 0; | ||
static get active() { | ||
return this.activeForgets > 0; | ||
} | ||
static async awaitInactive(interval = 100, timeout) { | ||
let timeoutRemaining = timeout; | ||
while (this.active) { | ||
await (0, import_delay.delay)(interval); | ||
if (timeoutRemaining !== void 0) { | ||
timeoutRemaining -= interval; | ||
if (timeoutRemaining <= 0) { | ||
return this.activeForgets; | ||
} | ||
} | ||
} | ||
return 0; | ||
} | ||
//used to explicitly launch an async function (or Promise) with awaiting it | ||
static forget(promise, timeout) { | ||
let completed = false; | ||
this.activeForgets++; | ||
const promiseWrapper = async () => { | ||
await promise.then(() => { | ||
this.activeForgets--; | ||
completed = true; | ||
}).catch(() => { | ||
this.activeForgets--; | ||
completed = true; | ||
}); | ||
}; | ||
const promises = [promiseWrapper()]; | ||
if (timeout) { | ||
const timeoutFunc = async () => { | ||
await (0, import_delay.delay)(timeout.delay); | ||
if (!completed) { | ||
console.log(`forget promise timeout out after ${timeout.delay}ms [Cancelling]`); | ||
timeout.cancel?.(); | ||
} | ||
}; | ||
promises.push(timeoutFunc()); | ||
} | ||
const all = Promise.race(promises); | ||
all.then(() => { | ||
return; | ||
}).catch(() => { | ||
return; | ||
}); | ||
} | ||
}; | ||
var forget = (promise, timeout) => { | ||
ForgetPromise.forget(promise, timeout); | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
ForgetPromise, | ||
forget | ||
}); | ||
//# sourceMappingURL=index.js.map |
@@ -51,7 +51,7 @@ { | ||
"dependencies": { | ||
"@xylabs/delay": "~2.11.3" | ||
"@xylabs/delay": "~2.11.4" | ||
}, | ||
"devDependencies": { | ||
"@xylabs/ts-scripts-yarn3": "^3.0.0", | ||
"@xylabs/tsconfig": "^3.0.0", | ||
"@xylabs/ts-scripts-yarn3": "^3.0.20", | ||
"@xylabs/tsconfig": "^3.0.20", | ||
"typescript": "^5.2.2" | ||
@@ -67,3 +67,3 @@ }, | ||
"sideEffects": false, | ||
"version": "2.11.3" | ||
"version": "2.11.4" | ||
} |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25962
223
17
1
Updated@xylabs/delay@~2.11.4