Skip to content

Instantly share code, notes, and snippets.

@gtokman
Last active March 28, 2021 20:27
Show Gist options
  • Save gtokman/262283f0182855df422a2099237d7957 to your computer and use it in GitHub Desktop.
Save gtokman/262283f0182855df422a2099237d7957 to your computer and use it in GitHub Desktop.
subscribe vs receive
["hello world"]
.publisher
.subscribe(on: DispatchQueue.global(qos: .background)) // 1
.map { string -> String in
print("Is main thread in map:", Thread.isMainThread)
return string
}
.breakpoint(receiveOutput: { str in
print("current str:", str)
return Thread.isMainThread // if main thread, breakpoint
})
.print("debug")
.receive(on: DispatchQueue.main) // 2
.sink { str in
print("Is main thread in sink:", Thread.isMainThread)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment