Created
January 11, 2018 02:05
-
-
Save ezura/b51745237d827073ea46426ab99d0bca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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