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

Improve multiple task handling (Task.all/any/some) in case of empty tasks-argument #60

Merged
merged 1 commit into from
Mar 19, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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