You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- `EventListener` can now invoke Callbacks on any of 3 Target Threads:
- `.requesterThread` is the Thread belonging to the Callback itself
- `.listenerThread` is the Thread belonging to the `EventListener`
- `.taskThread` is an Ad-hoc `Task` Thread
- README.MD updated for the above
@@ -355,7 +355,7 @@ An `EventListener` is a universal way of subscribing to *Events*, anywhere in yo
355
355
356
356
By design, `EventDrivenSwift` provides a *Central Event Listener*, which is automatically initialized should any of your code register a *Listener* for an *Event* by reference to the `Eventable` type.
357
357
358
-
**Important Note:**`EventListener` will always invoke the associated `Callbacks` on the same Thread (or `DispatchQueue`) from whence the *Listener* registered! This is an extremely useful behaviour, because it means that *Listeners* registered from the `MainActor` (or "UI Thread") will always execute on that Thread, with no additional overhead or code required by you.
358
+
**Important Note:**`EventListener` will (by default) invoke the associated `Callbacks` on the same Thread (or `DispatchQueue`) from whence the *Listener* registered! This is an extremely useful behaviour, because it means that *Listeners* registered from the `MainActor` (or "UI Thread") will always execute on that Thread, with no additional overhead or code required by you.
359
359
360
360
Let's register a simple *Listener* in some arbitrary `class`. For this example, let's produce a hypothetical *View Model* that will *Listen* for `TemperatureRatingEvent`, and would invalidate an owning `View` to show the newly-received values.
361
361
@@ -386,6 +386,19 @@ In the above example, whenever the *Reciprocal Event* named `TemperatureRatingEv
386
386
387
387
Don't worry about managing the lifetime of your *Listener*! If the object which owns the *Listener* is destroyed, the *Listener* will be automatically unregistered for you!
388
388
389
+
If you need your *Event Callback* to execute on the *Listener's* Thread, as of Version 3.1.0... you can!
**Remember:** When executing an *Event Callback* on `.listenerThread`, you will need to ensure that your *Callback* and all resources that it uses are 100% Thread-Safe!
394
+
**Important:** Executing the *Event Callback* on `.listnerThread` can potentially delay the invocation of other *Event Callbacks*. Only use this option when it is necessary.
395
+
396
+
You can also execute your *Event Callback* on an ad-hoc `Task`:
**Remember:** When executing an *Event Callback* on `.taskThread`, you will need to ensure that your *Callback* and all resources that it uses are 100% Thread-Safe!
401
+
389
402
Another thing to note about the above example is the `listenerToken`. Whenever you register a *Listener*, it will return a Unique Universal ID (a `UUID`) value. You can use this value to *Unregister* your *Listener* at any time:
0 commit comments