Initial commit
This commit is contained in:
commit
a9145c8a80
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
node_modules
|
33
index.js
Normal file
33
index.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
"use strict";
|
||||
|
||||
const pDefer = require("p-defer");
|
||||
|
||||
module.exports = function createPauser() {
|
||||
let isPaused = false;
|
||||
let promise, resolve;
|
||||
|
||||
return {
|
||||
await: function (passthroughValue) {
|
||||
if (isPaused) {
|
||||
return promise.then(() => {
|
||||
return passthroughValue;
|
||||
});
|
||||
} else {
|
||||
return passthroughValue;
|
||||
}
|
||||
},
|
||||
pause: function () {
|
||||
isPaused = true;
|
||||
|
||||
let defer = pDefer();
|
||||
promise = defer.promise;
|
||||
resolve = defer.resolve;
|
||||
},
|
||||
unpause: function () {
|
||||
if (isPaused) {
|
||||
isPaused = false;
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
11
package.json
Normal file
11
package.json
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "p-pause",
|
||||
"version": "0.1.0",
|
||||
"main": "index.js",
|
||||
"repository": "https://git.cryto.net/joepie91/p-pause.git",
|
||||
"author": "Sven Slootweg <admin@cryto.net>",
|
||||
"license": "WTFPL OR CC0-1.0",
|
||||
"dependencies": {
|
||||
"p-defer": "^3.0.0"
|
||||
}
|
||||
}
|
8
yarn.lock
Normal file
8
yarn.lock
Normal file
|
@ -0,0 +1,8 @@
|
|||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
p-defer@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/p-defer/-/p-defer-3.0.0.tgz#d1dceb4ee9b2b604b1d94ffec83760175d4e6f83"
|
||||
integrity sha512-ugZxsxmtTln604yeYd29EGrNhazN2lywetzpKhfmQjW/VJmhpDmWbiX+h0zL8V91R0UXkhb3KtPmyq9PZw3aYw==
|
Loading…
Reference in a new issue