forked from rockybars/atom-shell-packager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhooks.js
25 lines (21 loc) · 732 Bytes
/
hooks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
'use strict'
const pify = require('pify')
module.exports = {
promisifyHooks: function promisifyHooks (hooks, args) {
if (!hooks || !Array.isArray(hooks)) {
return Promise.resolve()
}
return Promise.all(hooks.map(hookFn => pify(hookFn).apply(this, args)))
},
serialHooks: function serialHooks (hooks) {
return function () {
const args = Array.prototype.splice.call(arguments, 0, arguments.length - 1)
const done = arguments[arguments.length - 1]
let result = Promise.resolve()
for (const hook of hooks) {
result = result.then(() => hook.apply(this, args))
}
return result.then(() => done()) // eslint-disable-line promise/no-callback-in-promise
}
}
}