You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
640 B
JavaScript
24 lines
640 B
JavaScript
"use strict";
|
|
|
|
const singleConcurrent = require("./");
|
|
|
|
(async function () {
|
|
let trySomeAsyncProcess = singleConcurrent(async function someAsyncProcess() {
|
|
// Let's pretend that this is some long-running task that internally recurses
|
|
console.log("started some async process");
|
|
await new Promise((resolve) => {
|
|
setTimeout(resolve, Math.random() * 2000);
|
|
});
|
|
console.log("finished some async process");
|
|
});
|
|
|
|
trySomeAsyncProcess();
|
|
trySomeAsyncProcess(); // oops! it was already running and we tried to run it again
|
|
})();
|
|
|
|
/* Output (note how it's only output once):
|
|
|
|
started some async process
|
|
finished some async process
|
|
*/
|