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

Provide a result for taskForCompletionOfAllTasks #23

Closed
jtbthethird opened this issue Mar 16, 2014 · 8 comments
Closed

Provide a result for taskForCompletionOfAllTasks #23

jtbthethird opened this issue Mar 16, 2014 · 8 comments

Comments

@jtbthethird
Copy link

I want to do multiple asynchronous tasks in parallel, each of which returns a value, and then when all have completed, get an array of those results.

As of now, taskForCompletionOfAllTasks just returns a result of nil.

@adriendulong
Copy link

I would like the same thing.
It would be really useful to get the results of my parallel tasks.
Right now I can't use it because I don't get any result.

Thanks !

@goopi
Copy link

goopi commented Sep 25, 2014

Same problem here.
One way to get each task result:

[[BFTask taskForCompletionOfAllTasks:tasks] continueWithBlock:^id(BFTask *task) {
    for (int i = 0; i < tasks.count; ++i) {
        NSLog(@"%@", [tasks[i] result]);
    }
    return nil;
}];

@rcbello
Copy link

rcbello commented Oct 24, 2014

How about this solution:

-(BFTask *)parallelTasksWitResult{

BFTaskCompletionSource *compSource = [BFTaskCompletionSource taskCompletionSource];

NSMutableDictionary *resultInfo = [NSMutableDictionary dictionary];
NSMutableArray *wrapperTasks = [NSMutableArray array];
NSArray *tasksToExecute = // tasks to execute

for (BFTask *task in tasksToExecute) {
    [wrapperTasks addObject:[task continueWithBlock:^id(BFTask *task) {

        //update result info

        return nil;
    }]];
}

[[BFTask taskForCompletionOfAllTasks:wrapperTasks] continueWithBlock:^id(BFTask *task) {
    [compSource setResult:resultInfo];
    return nil;
}];

return compSource.task;

}

@bklimt
Copy link
Contributor

bklimt commented Nov 25, 2014

You have access to all of the BFTasks you waited on, so you can get their results, as @goopi demonstrated.

@bklimt bklimt closed this as completed Nov 25, 2014
@gazialankus
Copy link

gazialankus commented Jun 10, 2016

In a task chain, the task above has a task array in its closure. The task below needs to get the results of the task array from task.result, but it can't. It can't access the task array either, because the task array is in the scope of the above closure.

In a task chain like this, we don't have access to the BFTasks that we waited on.

Or, you may want to get the task that taskForCompletionOfAllTasks gives, and send it somewhere else in your project. Sending the task array along with it is not a good solution. It's a shame that this issue is closed.

The analogous Parse.Promise.when([p1, p2]).then(f) passes the result array to f. This is the expected behavior. Respectfully summoning the top contributor @nlutsenko

@nlutsenko
Copy link
Member

@gazialankus
666ec8587d11b175c1b44dbcfec1df4bcd4a0a455737ca75eb3939a766fc0d31

@nlutsenko
Copy link
Member

This issue is probably actually resolved, since we have taskForCompletionAllTasksWithResults: now, which does exactly what you are describing - provides an array of results on successful completion of all tasks. Header reference here

@gazialankus
Copy link

OOH my bad! Sorry about that, and thank you for this awesome piece of software your highness :)

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

No branches or pull requests

7 participants