Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queue callback not called if method rejects promise #1111

Closed
dmarkhas opened this issue Jun 4, 2019 · 1 comment
Closed

Queue callback not called if method rejects promise #1111

dmarkhas opened this issue Jun 4, 2019 · 1 comment
Labels

Comments

@dmarkhas
Copy link

dmarkhas commented Jun 4, 2019

In the below code, if the method that is being executed returns a rejected promise, the "completed" callback is never called.
As a result, the queue is left in a "running" state - which means it will not execute any other tasks and the entire environment has to be destroyed and re-created.

In case of such a failure I think it would make more sense to "reset" the generator and environment state to allow reusing it for subsequent run() calls.

function addMethod(method, methodName, queueName) {
  queueName = queueName || 'default';
  debug(`Queueing ${methodName} in ${queueName}`);
  self.env.runLoop.add(queueName, completed => {
    debug(`Running ${methodName}`);
    self.emit(`method:${methodName}`);

    runAsync(function() {
        self.async = () => this.async();
        return method.apply(self, self.args);
      })()
      .then(completed)
      .catch(err => {
        debug(`An error occured while running ${methodName}`, err);

        // Ensure we emit the error event outside the promise context so it won't be
        // swallowed when there's no listeners.
        setImmediate(() => {
          self.emit('error', err);
          reject(err);
        });
      });
  });
}
@github-actions
Copy link
Contributor

This issue is stale because it has been open 15 days with no activity. Remove stale label or comment or this will be closed in 5 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant