ReactKit / SwiftTask

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Run closure of promise/future on main ui thread

iliraga opened this issue · comments

Is it possible to run the Promise-Closure on the main thread? Sometimes I want to perform a UI asynchronous operation like requesting permissions to user etc. If those are runned in separate threads, they are not shown to the user... I wasn't able to found any solution in documentation or sourcecode

You can use any threading techniques e.g. Grand Central Dispatch inside Task initialization
to deliver fulfill/reject events on your target thread/queue.

Please see below as an example:

// fulfills after 100ms
func asyncTask(value: String) -> MyTask
{
return MyTask { progress, fulfill, reject, configure in
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 100_000_000), dispatch_get_main_queue()) {
fulfill(value)
}
}
}