UNPKG

389 BJavaScriptView Raw
1/*
2 * returns a mutex-locked version of async function `fn`, which is assumed to
3 * return a promies.
4 */
5
6module.exports = function mutex (fn) {
7 var running
8 return function () {
9 if (running) return
10 running = true
11 fn.apply(this, arguments)
12 .then(function (data) { running = false; return data })
13 .catch(function (error) { running = false; throw error })
14 }
15}
16