pass async to end-user on start & end for sandbox
See original GitHub issueThis was discussed in slack.
Is your feature request related to a problem? Please describe.
Currently, require('@architect/sandbox')
end
and start
functions swallow the callbacks , so end-user has no access to err or when the close has asynchronously finished. This is a sign that global async queue is being used, and breaks things like testing in jest (as it uses atomic async tests & before/after, not global queue.) It’s not just a problem with testing though, it would break anything where you need to do something after start
or end
.
Describe the solution you’d like
If async were not swallowed, end-user could trigger their function when it’s done. I like promises, in general, and some will like callbacks, so this, as an example, supports both uses:
const { promisify } = require('util')
function end(cb = () => {}) {
return Promise.all(
promisify(client.close)(),
promisify(bus.close)(),
).then(() => {
if ((arc.http || arc.ws) {
return promisify(http.close)().then(promisify(cb))
}else{
return promisify(cb)()
}
})
}
this resolves when client
& bus
close
methods have been called in parallell, then http
and user’s callback. It returns a promise, and if the user gave a callback, it uses that (instead of requiring user to use a promise.)
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Diff module’s side effects, let’s scope that bug to that module. This fix will ship in
1.6.0
!I think we just crossed paths here and on Slack! I think I’ve managed to resolve all issues in
1.5.9-RC
, pleasenpm i @architect/sandbox@RC
and let me know how it goes.Per the Dynamo client thing, I worked around that by putting that operation into a callback fn, seems fine and more deterministic, so that’s a nice bonus. 📈