Skip to content

CanBusServiceExtensions Class

Callback-style convenience layer over Subscribe(Func<CanFrameEvent,bool>, Nullable<int>, bool) for callers who want "filter + handler" instead of driving the async-enumerable Frames stream themselves.

public static class CanBusServiceExtensions

Inheritance Object → CanBusServiceExtensions

Methods

CanBusServiceExtensions.Subscribe(this ICanBusService, Action<CanFrameEvent>, Func<CanFrameEvent,bool>, Nullable<int>, bool, Action<Exception>) Method

Registers a subscription and invokes onNext for every frame it accepts, on a dedicated background task. Disposing the returned handle stops delivery and lets that task end.

public static System.IDisposable Subscribe(this CanKit.Pro.RawCan.ICanBusService service, System.Action<CanKit.Pro.RawCan.CanFrameEvent> onNext, System.Func<CanKit.Pro.RawCan.CanFrameEvent,bool>? predicate=null, System.Nullable<int> bufferCapacity=null, bool includeEcho=false, System.Action<System.Exception>? onError=null);

Parameters

service ICanBusService

The service to subscribe on.

onNext Action<CanFrameEvent>

Invoked for each accepted frame, in arrival order.

predicate Func<CanFrameEvent,Boolean>

Per-frame filter, or null to accept all frames.

bufferCapacity Nullable<Int32>

Bounded buffer capacity for the underlying subscription; null uses DefaultBufferCapacity.

includeEcho Boolean

Whether the callback also sees the local host's own transmit echoes; false by default, for the reason given on ICanBusService.

onError Action<Exception>

Where a failure of onNext -- or of the delivery pump itself -- is reported. When given it is the single destination, in preference to the service's fault event, because a caller who passes it has said where these belong.

It is also the only destination available for an ICanBusService implementation other than CanBusService: BackgroundExceptionOccurred is an event, and only the type that declares it can raise it, so this extension cannot report through a foreign implementation's fault channel however much it would like to. Without onError such an exception has nowhere to go and is dropped -- the alternative, letting it out of the pump, would silently end delivery instead.

Returns

IDisposable
Disposing this stops the subscription and the background delivery task.

Remarks

Built entirely on the existing ISubscription pull API, so the same per-subscription bounded, drop-oldest buffer applies (FR-RAW-011): a slow onNext only ever falls behind and drops its own oldest frames -- it can never delay delivery to other subscriptions or to the bus's own FrameObserved event, because the dispatch hot path never waits on a subscriber's consumer. An exception thrown by onNext is isolated per frame -- delivery continues with the next frame -- and reported through onError if one was given, otherwise through BackgroundExceptionOccurred when service is a CanBusService.