-
- All Implemented Interfaces:
-
com.onesignal.common.events.IEventNotifier
public class EventProducer<THandler extends Object> implements IEventNotifier<THandler>
A standard implementation that implements IEventNotifier and additional functionality to make event firing less burdensome to the user.
-
-
Field Summary
Fields Modifier and Type Field Description private final BooleanhasSubscribers
-
Constructor Summary
Constructors Constructor Description EventProducer()
-
Method Summary
Modifier and Type Method Description BooleangetHasSubscribers()Unitsubscribe(THandler handler)Subscribe to listen for events. Unitunsubscribe(THandler handler)Unsubscribe to no longer listen for events. final UnitsubscribeAll(EventProducer<THandler> from)Subscribe all from an existing producer to this subscriber. final Unitfire(Function1<THandler, Unit> callback)Call this to fire the callback which will allow the caller to drive the calling of the callback handlers if there are any. final UnitfireOnMain(Function1<THandler, Unit> callback)Call this to fire the callback which will allow the caller to drive the calling of the callback handlers if there are any. final UnitsuspendingFire(SuspendFunction1<THandler, Unit> callback)Call this to fire the callback which will allow the caller to drive the calling of the callback handlers if there are any. final UnitsuspendingFireOnMain(SuspendFunction1<THandler, Unit> callback)Call this to fire the callback which will allow the caller to drive the calling of the callback handlers if there are any. -
-
Method Detail
-
getHasSubscribers
Boolean getHasSubscribers()
-
subscribe
Unit subscribe(THandler handler)
Subscribe to listen for events.
- Parameters:
handler- The handler that will be called when the event(s) occur.
-
unsubscribe
Unit unsubscribe(THandler handler)
Unsubscribe to no longer listen for events.
- Parameters:
handler- The handler that was previous registered via subscribe.
-
subscribeAll
final Unit subscribeAll(EventProducer<THandler> from)
Subscribe all from an existing producer to this subscriber.
-
fire
final Unit fire(Function1<THandler, Unit> callback)
Call this to fire the callback which will allow the caller to drive the calling of the callback handlers if there are any.
- Parameters:
callback- The callback will be invoked for each subscribed handler, allowing you to call the handler.
-
fireOnMain
final Unit fireOnMain(Function1<THandler, Unit> callback)
Call this to fire the callback which will allow the caller to drive the calling of the callback handlers if there are any. The callback will be invoked asynchronously on the main thread. Control will be returned immediately, most likely prior to the callbacks being invoked.
- Parameters:
callback- The callback will be invoked for each subscribed handler, allowing you to call the handler.
-
suspendingFire
final Unit suspendingFire(SuspendFunction1<THandler, Unit> callback)
Call this to fire the callback which will allow the caller to drive the calling of the callback handlers if there are any.
- Parameters:
callback- The callback will be invoked for each subscribed handler, allowing you to call the handler.
-
suspendingFireOnMain
final Unit suspendingFireOnMain(SuspendFunction1<THandler, Unit> callback)
Call this to fire the callback which will allow the caller to drive the calling of the callback handlers if there are any. The callback will be invoked on the main thread.
- Parameters:
callback- The callback will be invoked for each subscribed handler, allowing you to call the handler.
-
-
-
-