Closed ldiqual closed 7 years ago
+1
This works for me:
private static func async<O>(after seconds: Double? = nil, block: @escaping () -> O, queue: GCD) -> AsyncBlock<Void, O> {
let reference = Reference<O>()
let block = DispatchWorkItem(block: {
reference.value = block()
})
if let seconds = seconds {
let time = DispatchTime.now() + seconds
queue.queue.asyncAfter(deadline: time, execute: block)
} else {
queue.queue.async(execute: block)
}
// Wrap block in a struct since @convention(block) () -> Swift.Void can't be extended
return AsyncBlock<Void, O>(block, output: reference)
}
I also need swift4, hoping to use it as soon as possible
Same issue.
From migration-guide-swift4
reference.value = block()
change to reference.value = block(())
Maybe right!
+1
+1
thanks
2017-09-27 10:36 GMT+08:00 returnight notifications@github.com:
+1
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/duemunk/Async/issues/119#issuecomment-332391760, or mute the thread https://github.com/notifications/unsubscribe-auth/AZh7y_yfriw17rH-TzOMTyQBUehAsLLLks5smbSigaJpZM4N5e9R .
@duemunk Any updates on this? Thanks!
Fixed by #122
Side note: I also tried to convert the Async project with Xcode 9 + Swift 4 but we get a bunch of errors due to
Void => ()
conversion which requires declaring closure params explicitly, very annoying. Not sure if that's a swift 4 beta bug or something that needs to be worked on.