@@ -64,6 +64,8 @@ Object.keys(actions).forEach(function (actionName) {
64
64
})
65
65
})
66
66
}
67
+
actions[actionName].init = action.init || (() => BB.resolve())
68
+
actions[actionName].teardown = action.teardown || (() => BB.resolve())
67
69
})
68
70
exports.actions = actions
69
71
@@ -106,7 +108,10 @@ function handleOptionalDepErrors (pkg, err) {
106
108
exports.doOne = doOne
107
109
function doOne (cmd, staging, pkg, log, next) {
108
110
validate('SSOOF', arguments)
109
-
execAction(prepareAction([cmd, pkg], staging, log)).then(() => next(), next)
111
+
const prepped = prepareAction([cmd, pkg], staging, log)
112
+
return withInit(actions[cmd], () => {
113
+
return execAction(prepped)
114
+
}).nodeify(next)
110
115
}
111
116
112
117
exports.doParallel = doParallel
@@ -120,8 +125,11 @@ function doParallel (type, staging, actionsToRun, log, next) {
120
125
}, [])
121
126
log.silly('doParallel', type + ' ' + actionsToRun.length)
122
127
time(log)
123
-
BB.map(acts, execAction, {
124
-
concurrency: npm.limit.action
128
+
if (!acts.length) { return next() }
129
+
return withInit(actions[type], () => {
130
+
return BB.map(acts, execAction, {
131
+
concurrency: npm.limit.action
132
+
})
125
133
}).nodeify((err) => {
126
134
log.finish()
127
135
timeEnd(log)
@@ -151,7 +159,10 @@ function runSerial (type, staging, actionsToRun, log, next) {
151
159
return acc
152
160
}, [])
153
161
time(log)
154
-
BB.each(acts, execAction).nodeify((err) => {
162
+
if (!acts.length) { return next() }
163
+
return withInit(actions[type], () => {
164
+
return BB.each(acts, execAction)
165
+
}).nodeify((err) => {
155
166
log.finish()
156
167
timeEnd(log)
157
168
next(err)
@@ -165,6 +176,13 @@ function timeEnd (log) {
165
176
process.emit('timeEnd', 'action:' + log.name)
166
177
}
167
178
179
+
function withInit (action, body) {
180
+
return BB.using(
181
+
action.init().disposer(() => action.teardown()),
182
+
body
183
+
)
184
+
}
185
+
168
186
function prepareAction (action, staging, log) {
169
187
validate('ASO', arguments)
170
188
validate('SO', action)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4