8000 Best way to handle an error · Issue #39 · dominictarr/through · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Oct 31, 2018. It is now read-only.
This repository was archived by the owner on Oct 31, 2018. It is now read-only.

Best way to handle an error #39

Open

Description

@eddieajau

Just wondering what's the best way to handle an error in a paused stream that is waiting for a promise to resolve. The example I have is something like the following case:

// Going to map some rows from a CSV reader
function mapRow() {
  return function (data) {
    // Yes, we want `this` in the context of the calling `through` function.
    var self = this;

    // Pausing the stream while we handle the promise.
    self.pause();

    somePromisaryService(data)
      .then(function () {
        self.emit(data);
        self.resume();
      })
      .catch(function (err) {
        //
621D
 Ok, how do we deal with this???
      });
  }
}

aCsvReader()
  .pipe(through(mapRow()));

Is there anything available in the context of through that I can use or do I need to introduce something external to catch any error in the promise?

Thanks in advance.

Activity

  1. dominictarr commented on Oct 5, 2015

    @dominictarr
    Owner

    Use self.emit('error', err)
    You other self.emit(data) should be self.queue(data) BTW.
    On Oct 5, 2015 12:47 PM, "Andrew Eddie" notifications@github.com wrote:

    Just wondering what's the best way to handle an error in a paused stream
    that is waiting for a promise to resolve. The example I have is something
    like the following case:

    // Going to map some rows from a CSV readerfunction mapRow() {
    return function (data) {
    // Yes, we want this in the context of the calling through function.
    var self = this;

    // Pausing the stream while we handle the promise.
    self.pause();
    
    somePromisaryService(data)
      .then(function () {
        self.emit(data);
        self.resume();
      })
      .catch(function (err) {
        // Ok, how do we deal with this???
      });
    

    }
    }

    aCsvReader()
    .pipe(through(mapRow()));

    Is there anything available in the context of through that I can use or
    do I need to introduce something external to catch any error in the promise?

    Thanks in advance.

    —
    Reply to this email directly or view it on GitHub
    #39.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0