Skip to content

Instantly share code, notes, and snippets.

@inamiy
Last active March 22, 2022 04:02
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 inamiy/6ee65da1424b3f8837f51e9fe13b1a25 to your computer and use it in GitHub Desktop.
Save inamiy/6ee65da1424b3f8837f51e9fe13b1a25 to your computer and use it in GitHub Desktop.
import Foundation
import _Concurrency
// https://twitter.com/inamiy/status/1506118628839546880
var f: () -> () = {}
var fSendable: @Sendable () -> () = {}
var fMain: @MainActor () -> () = {}
var fMainSendable: @MainActor @Sendable () -> () = {}
// @Sendable clsoure -> normal closure
f = fSendable
//fSendable = f // ERROR
// @Sendable closure -> @MainActor closure
fMain = fSendable
//fSendable = fMain // ERROR
// normal closure -> @MainActor closure
fMain = f
//f = fMain // ERROR
// @Sendable closure -> @MainActor @Sendable closure
fMainSendable = fSendable
//fSendable = fMainSendable // ERROR
//f = fMainSendable // ERROR
//fMainSendable = f // ERROR
// @MainActor @Sendable closure -> @MainActor closure
fMain = fMainSendable
//fMainSendable = fMain // ERROR
// Conclusion:
//
// 1. @Sendable -> normal -> @MainActor
// 2. @Sendable -> @MainActor @Sendable -> @MainActor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment