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

Add anyway version of map and parallel #531

Closed
wants to merge 2 commits into from
Closed

Conversation

allevo
Copy link

@allevo allevo commented May 13, 2014

Use mapAnyway or parallelAnyway for doing something in parallel but if some tasks fail, the others will be executed anyway. In the final callback, the first parameter is valued with all errors. For mapAnyway, the second parameter with all mapped object.
Add main test for parallelAnyway and mapAnyway.

@caolan
Copy link
Owner

caolan commented May 16, 2014

Hi @allevo, I'm not sure about the name. Perhaps something like mapResumable or mapContinue or something?

@allevo
Copy link
Author

allevo commented May 16, 2014

Yes the problem is the name! Give me your preferred name for those functions.
But i have another inconvenient: async.each isn't converted. Please give me some time.

Are you interested in this pull request?
Would you prefer I pull to a non-master branch?

@caolan
Copy link
Owner

caolan commented May 23, 2014

@allevo yes, I'm interested in this, it's been asked for a few times. Mostly it's a question of API and naming rather than code.

@allevo
Copy link
Author

allevo commented May 27, 2014

I've used "anyway" suffix to indicate the process goes on anyway if an error occurs.
Please tell me what name you prefer and I'll change it!

@aearly
Copy link
Collaborator

aearly commented May 27, 2014

Another question -- would mapAnyway and parallelAnyway return null values for those tasks that fail? Error objects? Omit them?

As for naming -- how about mapMaybe or parallelMaybe? Signifies that there may be undefined results, and that you want to be able to continue.

@allevo
Copy link
Author

allevo commented Jun 2, 2014

Each function returns an array (or object) where the errors are. https://github.com/allevo/async/blob/master/test/test-async.js#L807 https://github.com/allevo/async/blob/master/test/test-async.js#L1097 Here you can find the test of error case.
Perhaps the error array maintain the position of the failed functions. As you like!
Now, if the only second function fails, the error array in the final callback has the first value set to the error instead of be [null, Error]. Contrariwise if there's an object, the error is an object whose values are the errors or null

@aearly aearly mentioned this pull request Jun 11, 2014
@lxe
Copy link

lxe commented Jul 7, 2014

Can't this be already accomplished with the existing methods?

async.map([1, 2, 3, 4, 5], function (name, callback) {
  fs.readFile(thing, function (err, data) {
    callback(null, {
      error: err,
      data: data
    });
  });
}, function (err, results) {
  // results[n].err  is the error
  // results[n].data is the value
});

@allevo
Copy link
Author

allevo commented Jul 23, 2014

Sorry for the late.
Yes you can do this but it's very horrible to see!
And you'll use a map to have only the results

Remove some console.log
@allevo
Copy link
Author

allevo commented Jul 29, 2014

If you don't like the interface, please tell me which you prefer! 👍
I'll apply as soon as possible

@allevo
Copy link
Author

allevo commented Dec 28, 2014

Is this PR blocked? I need this!

@aearly aearly added the feature label May 21, 2015
@aearly aearly mentioned this pull request Jun 2, 2015
@aearly
Copy link
Collaborator

aearly commented Jun 2, 2015

I like this idea, but I dislike the global collect and uncollect states. Closing this in #349. We'll think up a general solution.

@aearly aearly closed this Jun 2, 2015
@aearly aearly reopened this Jun 2, 2015
@aearly
Copy link
Collaborator

aearly commented Jun 2, 2015

Nevermind, got PRs mixed up.

@kmgilbert100
Copy link

+1

1 similar comment
@gocoffeecup
Copy link

+1

@kmgilbert100
Copy link

Why hasn't this been added yet?

@allevo
Copy link
Author

allevo commented Oct 19, 2015

Because @caolan hasn't decided the names yet. As soon as possible, I'll resolve the conflict and repush the PR

@aearly
Copy link
Collaborator

aearly commented Oct 25, 2015

I realized that this breaks one of map's guarantees -- that the results returned in the same order as their inputs in the original array. If half your tasks callback an error, you'll get a results array that is half the size of the original array. It also is a bit of a convention break to return an array of errors (rather than a single Error object) as the first arg to a callback.

We're going to go back to the drawing board with #942

@aearly aearly closed this Oct 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants