Post

Replies

Boosts

Views

Activity

Reentrance and assumptions after suspension point
At 12:48 the presenter says "Any assumptions you've made about global state, clocks, timers, or your actor will need to be checked after the await." and shows that with the improved example of the image downloader where let image = try await downloadImage(from: url) // Replace the image only if it is still missing from the cache. cache[url] = cache[url, default: image] the cache is checked before it is updated. The presenter then says the even better solution avoids redundant downloads altogether and refers to the accompanied code example. In the attached code example: do { let image = try await handle.get() cache[url] = .ready(image) return image } catch { cache[url] = nil throw error } there is no check about the assumptions although it is after the suspension point try await handle.get(). Why can cache[url] = .ready(image) or cache[url] = nil be set without any checks? Why is that no assumption about global state? Why can this be ignored in this case?
5
0
1.1k
Jun ’21