ReactKit / SwiftTask

Promise + progress + pause + cancel + retry for Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question]Task Manager

LemonRuss opened this issue · comments

Is there easy way to make some manager around task? For example - i created about ten tasks with Alamofire.upload and some other stuff. I should put them in array and remove each value in success closure, so if array clear - all tasks complete successfully.
Problem, is that i can't to smth like this
let uploadTask = LoadImageTask(attachId: event.postId!, attachUrl: "events/(event.postId)/photos",
image: image)
.success({ (let imageId) -> Void in
self.tasksQueue.removeObject(uploadTask)
})
Variable use inside it's own initial value.
How i can deal with it?

There are multiple tasks handling functions like Task.all to get notified when all tasks completed successfully.

It depends on how precisely you want to manage running/pending tasks, but your example code seems unnecessary to create a new manager because GCD queue inside Alamofire will normally take care of their lifetimes.

Okey, I should explain better. I have a lot of tasks, each have about 3 Alamofire requests. I should know that all of them are finished, and if i have some failure - i should store information about them, so person can resend information.
It can be done by NSOperation, but it sound strange to put each task in own operationQueue, when Alamofire has it.