Combine Schedulers: Erasing Time

Episode #106 • Jun 15, 2020 • Subscriber-Only

We refactor our application’s code so that we can run it in production with a live dispatch queue for the scheduler, while allowing us to run it in tests with a test scheduler. If we do this naively we will find that generics infect many parts of our code, but luckily we can employ the technique of type erasure to make things much nicer.

Erasing Time
Using the test scheduler
The problem with generics
Using the AnyScheduler
Ergonomic interlude
What’s the point?

Unlock This Episode

Our Free plan includes 1 subscriber-only episode of your choice, plus weekly updates from our newsletter.


This was a lot of work to create this test scheduler, and honestly there may even be a few more subtle bugs lurking in the shadows. Scheduling is an incredibly complex topic, and we have really jumped into the deep end on this episode.

One way to take these ideas further would be to employ some formal methods for verifying scheduling behavior and to check that our test scheduler works correctly. We’ll leave that for another time though.

Now that we’ve got a test scheduler defined and implemented, let’s try to use it to make our view model more testable. Right now we are using DispatchQueue.main in a few spots in our view model, and as we have seen this is quite a complex dependency to have in our view model, and complicates testing.

This episode is for subscribers only.

Subscribe to Point-Free

Access this episode, plus all past and future episodes when you become a subscriber.

See plans and pricing

Already a subscriber? Log in



Brandon Williams & Stephen Celis • Sunday Jun 14, 2020

An open source library that provides schedulers for making Combine more testable and more versatile.