forked from MarkBind/markbind
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request MarkBind#31 from rachx/live-reload
Ignore updates to source files while live-reloading is in progress MarkBind#155
- Loading branch information
Showing
5 changed files
with
99 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const Promise = require('bluebird'); | ||
|
||
/** | ||
* Creates a function that delays invoking `func` until after `wait` milliseconds have elapsed | ||
* and the running `func` has resolved/rejected. | ||
* @param func the promise-returning function to delay, | ||
* func should take in a single array | ||
* @param wait the number of milliseconds to delay | ||
* @returns delayedFunc that takes in a single argument (either an array or a single value) | ||
*/ | ||
module.exports = function delay(func, wait) { | ||
let context; | ||
let pendingArgs = []; | ||
let waitingPromise = null; | ||
let runningPromise = Promise.resolve(); | ||
|
||
return function (arg) { | ||
context = this; | ||
if (Array.isArray(arg)) { | ||
pendingArgs = pendingArgs.concat(arg); | ||
} else { | ||
pendingArgs.push(arg); | ||
} | ||
|
||
if (waitingPromise === null) { | ||
waitingPromise = Promise.all([Promise.delay(wait), runningPromise]) | ||
.finally(() => { | ||
runningPromise = waitingPromise || Promise.resolve(); | ||
waitingPromise = null; | ||
const funcPromise = func.apply(context, [pendingArgs]); | ||
pendingArgs = []; | ||
return funcPromise; | ||
}); | ||
} | ||
|
||
return waitingPromise; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters