Custom Publishers/Subscribers


After reading your book (v0.3), I felt inspired to use Combine in some of my newer projects. Fast forward some weeks and I have written several custom publishers/operators/subscribers.

Since at the time I struggled finding working examples for custom publishers, I have decided to gather some of them in a Github repo in case it is helpful to someone.

Cheers and keep up the great work. I can wait to read the last chapters.


Feedback like this really brightens my day, thank you for taking the time to write us! That repo looks really useful and shared it onwards to the slack and twitter. The final version of the books should arrive within days with the rest of the chapters :+1:t3:

1 Like

Thank you for your kind works and for sharing.

I am really looking forward finishing the book. It is really good, so far.

This is great. Thank you!

1 Like

This is wonderful, @dehesa! Congratulations for this achievement and many more to come!

1 Like

A little update on this project:

There are now custom subscribers on the repo using backpressure, which I find myself using more and more (e.g. it is quite an interesting tool to control the amount of in-flight API calls).

Also I have added some interesting operators/publishers such as:

  • retry on error and wait a given amount of seconds between attempts.
    apiPublisher.retry(on: queue, interval: [1, 3, 5])
  • handleEnd to execute a side-effect (exactly once) for any kind of completion (whether successful completion, failure, or cancel) so you can always clean up state.
    upstream.handleEnd { /* clean up */ }

Once one creates some custom publishers/subscribers, it is quite surprising how mechanical (and fast) the creation can be if you distill the core competences. I have extracted the basic states of any Combine entity on a property wrapper that can be easily used if you decide to create your own custom Combine publishers or subscribers.

@dehesa Congratulations and keep up the good work! :]

1 Like