Skip to content

Instantly share code, notes, and snippets.

@networkextension
Created December 6, 2016 07:28
Show Gist options
  • Select an option

  • Save networkextension/c6f837eccb1c6d147dd777a90ab29f24 to your computer and use it in GitHub Desktop.

Select an option

Save networkextension/c6f837eccb1c6d147dd777a90ab29f24 to your computer and use it in GitHub Desktop.
dispatch after calss swift3
import Cocoa
var str = "Hello, playground"
let x = UINT32_MAX
class FBQueue {
typealias qblock = ((Void) ->Void)
typealias qfinishBlock = ((Bool) ->Void)?
let call:qblock
let q = DispatchQueue.init(label: "test", qos: .background, attributes: .init(rawValue: 0), autoreleaseFrequency: .never, target: nil)
let callBack:qfinishBlock
var cancle:Bool = false
init(c:@escaping qblock, commpulte:qfinishBlock,after:DispatchTime) {
call = c
callBack = commpulte
q.asyncAfter(deadline: after) {
if self.cancle {
self.callBack!(self.cancle)
}else {
self.call()
self.callBack!(self.cancle)
}
}
}
}
let sfQ = FBQueue.init(c: {
print("execute")
}, commpulte: { (cancel:Bool) in
if cancel {
print("cancel")
}
}, after: .now() + 3 )
print(Date())
for i in 0 ..< 100 {
print(Date())
sleep(1)
if i == 2 {
sfQ.cancle = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment