Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implementing your own subscriber #97

Open
heckj opened this issue Aug 11, 2019 · 1 comment
Open

implementing your own subscriber #97

heckj opened this issue Aug 11, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@heckj
Copy link
Owner

heckj commented Aug 11, 2019

I started to add a section on Implementing your own subscriber, but realized there's a lot more learning that I need to do before I can knock it out.

I'm going to kick that back in priority to getting other elements done first.

Here's the snippet that I was thinking to start with, in developingwith.adoc:

== Implementing your own Subscriber

Developing with combine can frequently leverage the two common existing subscribers <<reference.adoc#reference-assign>> and <<reference.adoc#reference-sink>>, or you are working with an Apple framework (such as https://developer.apple.com/documentation/swiftui[SwiftUI]) that is the the subscriber to which you are integrating.

In some cases, you may want to create your own subscriber.
While <<reference.adoc#reference-sink>> can handle most situations, if you want to control the demand that drives the pipelines, you need to provide your own implementation.

__YET TO BE DEVELOPED__

https://developer.apple.com/documentation/combine/subscriber[`Subscriber protocol`]

types:
* Input
* Failure

protocol required functions:
* `receive(Self.Input) -> Subscribers.Demand`
* `receive(subscription: Subscription)`
* `receive(completion: Subscribers.Completion<Self.Failure>)`

* receive() -> Subscribers.Demand (when input void)

maybe based on https://developer.apple.com/documentation/combine/anysubscriber[`AnySubscriber`] which can be initialized with 3 closures:

* receiveSubscription: `((Subscription) -> Void)?``
* receiveValue: `((Input) -> Subscribers.Demand)?``
* receiveCompletion: `((Subscribers.Completion<Failure>) -> Void)?)``
@heckj heckj added the enhancement New feature or request label Aug 11, 2019
@heckj heckj added this to To do in first edition content Nov 20, 2019
@heckj
Copy link
Owner Author

heckj commented Dec 26, 2019

The few notes in the docs from:

  1. implement/conform to the Subscriber protocol
  2. handling cancel() (part of Subscriber protocol):

If you create a custom Subscriber, the publisher sends a Subscription object when you first subscribe to it. Store this subscription, and then call its cancel() method when you want to cancel publishing. When you create a custom subscriber, you should implement the Cancellable protocol, and have your cancel() implementation forward the call to the stored subscription.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

No branches or pull requests

1 participant