Skip to content

Commit

Permalink
feat: expose remaining resources in timeout error object; implements j…
Browse files Browse the repository at this point in the history
  • Loading branch information
jmealo committed Aug 6, 2020
1 parent f0450ab commit d2084f0
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/wait-on.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const PREFIX_RE = /^((https?-get|https?|tcp|socket|file):)(.+)$/;
const HOST_PORT_RE = /^(([^:]*):)?(\d+)$/;
const HTTP_GET_RE = /^https?-get:/;
const HTTP_UNIX_RE = /^http:\/\/unix:([^:]+):([^:]+)$/;
const TIMEOUT_ERR_MSG = 'Timeout';

const WAIT_ON_SCHEMA = Joi.object({
resources: Joi.array().items(Joi.string().required()).required(),
Expand Down Expand Up @@ -125,16 +124,14 @@ function waitOnImpl(opts, cbFunc) {
let lastResourcesState = resources; // the last state we had recorded

const timeoutError$ =
timeout !== Infinity ? timer(timeout).pipe(mergeMap(() => throwError(Error('Timeout')))) : NEVER;
timeout !== Infinity ? timer(timeout).pipe(mergeMap(() => {
const resourcesWaitingFor = determineRemainingResources(resources, lastResourcesState).join(', ')
return throwError(Error(`timed out waiting for: ${resourcesWaitingFor}`))
})) : NEVER;

function cleanup(err) {
if (err) {
if (err.message === TIMEOUT_ERR_MSG) {
const resourcesWaitingFor = determineRemainingResources(resources, lastResourcesState).join(', ');
log('wait-on(%s) timed out waiting for: %s; exiting with error', process.pid, resourcesWaitingFor);
} else {
log('wait-on(%s) exiting with error', process.pid, err);
}
} else {
// no error, we are complete
log('wait-on(%s) complete', process.pid);
Expand Down

0 comments on commit d2084f0

Please sign in to comment.