Skip to content

Instantly share code, notes, and snippets.

@ezura
Created January 11, 2018 02:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezura/b51745237d827073ea46426ab99d0bca to your computer and use it in GitHub Desktop.
Save ezura/b51745237d827073ea46426ab99d0bca to your computer and use it in GitHub Desktop.
/*
event | without didSet | have didSet
start 0 0
0 0
set 1 1
1 0
1 0
1 0
end 1 1
--- 1
*/
func f(_ v: inout Int, _ didSet: inout Int) {
print("start", v, didSet)
v += 1
didSet += 1
print("set", v, didSet)
sleep(4)
print("end", v, didSet)
}
var v = 0
var v_didSet = 0 {
didSet {}
}
DispatchQueue.global().async {
print(v, v_didSet)
}
DispatchQueue.global().asyncAfter(deadline: .now() + .seconds(1)) {
print(v, v_didSet)
}
DispatchQueue.global().asyncAfter(deadline: .now() + .seconds(2)) {
print(v, v_didSet)
}
DispatchQueue.global().asyncAfter(deadline: .now() + .seconds(3)) {
print(v, v_didSet)
}
f(&v, &v_didSet)
sleep(7)
print("---", v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment