Run closure of promise/future on main ui thread
iliraga opened this issue · comments
iliraga commented
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
Yasuhiro Inami commented
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:
SwiftTask/Playgrounds/02-Async.playground/Contents.swift
Lines 25 to 33 in 16c08c0