Invoking a callback from a publisher

When subscription leave the scope of receive(subscription:).

Your example works because delay created a temporary retain cycle, which I consider as a bug. It won't work for other publishers:

func test() -> AnyPublisher<Int, Error> {
    Timer.publish(every: 1, on: .main, in: .common)
        .map { _ in 42 }
        .setFailureType(to: Error.self)
        .eraseToAnyPublisher()
}

let s = ResultSubscriber<Int>() { result in
    dump(result)
}

print(Date())
test().subscribe(s)
print(Date())

// You forgot to start the runloop
RunLoop.main.run()