Skip to content

Commit

Permalink
Merge pull request ReactKit#60 from ReactKit/multiple-task-handling-w…
Browse files Browse the repository at this point in the history
…ith-empty-case

Improve multiple task handling (`Task.all`/`any`/`some`) in case of empty `tasks`-argument
  • Loading branch information
inamiy committed Mar 19, 2016
2 parents da6438b + 631ce37 commit 15aa6bf
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions SwiftTask/SwiftTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,10 @@ extension Task

public class func all(tasks: [Task]) -> Task<BulkProgress, [Value], Error>
{
guard !tasks.isEmpty else {
return Task<BulkProgress, [Value], Error>(value: [])
}

return Task<BulkProgress, [Value], Error> { machine, progress, fulfill, _reject, configure in

var completedCount = 0
Expand Down Expand Up @@ -737,6 +741,8 @@ extension Task

public class func any(tasks: [Task]) -> Task
{
precondition(!tasks.isEmpty, "`Task.any(tasks)` with empty `tasks` should not be called. It will never be fulfilled or rejected.")

return Task<Progress, Value, Error> { machine, progress, fulfill, _reject, configure in

var completedCount = 0
Expand Down Expand Up @@ -783,6 +789,10 @@ extension Task
/// This new task will NEVER be internally rejected.
public class func some(tasks: [Task]) -> Task<BulkProgress, [Value], Error>
{
guard !tasks.isEmpty else {
return Task<BulkProgress, [Value], Error>(value: [])
}

return Task<BulkProgress, [Value], Error> { machine, progress, fulfill, _reject, configure in

var completedCount = 0
Expand Down

0 comments on commit 15aa6bf

Please sign in to comment.