breakpoint(receiveSubscription:receiveOutput:receiveCompletion:)
Raises a debugger signal when a provided closure needs to stop the process in the debugger.
Declaration
func breakpoint(receiveSubscription: ((any Subscription) -> Bool)? = nil, receiveOutput: ((Self.Output) -> Bool)? = nil, receiveCompletion: ((Subscribers.Completion<Self.Failure>) -> Bool)? = nil) -> Publishers.Breakpoint<Self>Parameters
- receiveSubscription:
A closure that executes when the publisher receives a subscription. Return
truefrom this closure to raiseSIGTRAP, or false to continue. - receiveOutput:
A closure that executes when the publisher receives a value. Return
truefrom this closure to raiseSIGTRAP, or false to continue. - receiveCompletion:
A closure that executes when the publisher receives a completion. Return
truefrom this closure to raiseSIGTRAP, or false to continue.
Return Value
A publisher that raises a debugger signal when one of the provided closures returns true.
Discussion
Use breakpoint(receiveSubscription:receiveOutput:receiveCompletion:) to examine one or more stages of the subscribe/publish/completion process and stop in the debugger, based on conditions you specify. When any of the provided closures returns true, this operator raises the SIGTRAP signal to stop the process in the debugger. Otherwise, this publisher passes through values and completions as-is.
In the example below, a PassthroughSubject publishes strings to a breakpoint republisher. When the breakpoint receives the string “DEBUGGER”, it returns true, which stops the app in the debugger.
let publisher = PassthroughSubject<String?, Never>()
cancellable = publisher
.breakpoint(
receiveOutput: { value in return value == "DEBUGGER" }
)
.sink { print("\(String(describing: $0))" , terminator: " ") }
publisher.send("DEBUGGER")
// Prints: "error: Execution was interrupted, reason: signal SIGTRAP."
// Depending on your specific environment, the console messages may
// also include stack trace information, which is not shown here.