Skip to content

Commit 21c48c0

Browse files
committed
README.md updated to reflect changes
Documentation for the `UUID` *token* has been superseded by the new `EventListenerHandling` solution.
1 parent e30522c commit 21c48c0

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ class TemperatureRatingViewModel: ObservableObject {
370370
@Published var temperatureInCelsius: Float
371371
@Published var temperatureRating: TemperatureRating
372372

373-
var listenerToken: UUID
373+
var listenerHandle: EventListenerHandling?
374374

375375
internal func onTemperatureRatingEvent(_ event: TemperatureRatingEvent, _ priority: EventPriority) {
376376
temperatureInCelsius = event.temperatureInCelsius
@@ -379,7 +379,7 @@ class TemperatureRatingViewModel: ObservableObject {
379379

380380
init() {
381381
// Let's register our Event Listener Callback!
382-
listenerToken = TemperatureRatingEvent.addListener(self, onTemperatureRatingEvent)
382+
listenerHandle = TemperatureRatingEvent.addListener(self, onTemperatureRatingEvent)
383383
}
384384
}
385385
```
@@ -393,22 +393,24 @@ Don't worry about managing the lifetime of your *Listener*! If the object which
393393

394394
If you need your *Event Callback* to execute on the *Listener's* Thread, as of Version 3.1.0... you can!
395395
```swift
396-
listenerToken = TemperatureRatingEvent.addListener(self, onTemperatureRatingEvent, executeOn: .listenerThread)
396+
listenerHandle = TemperatureRatingEvent.addListener(self, onTemperatureRatingEvent, executeOn: .listenerThread)
397397
```
398398
**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!
399399
**Important:** Executing the *Event Callback* on `.listnerThread` can potentially delay the invocation of other *Event Callbacks*. Only use this option when it is necessary.
400400

401401
You can also execute your *Event Callback* on an ad-hoc `Task`:
402402
```swift
403-
listenerToken = TemperatureRatingEvent.addListener(self, onTemperatureRatingEvent, executeOn: .taskThread)
403+
listenerHandle = TemperatureRatingEvent.addListener(self, onTemperatureRatingEvent, executeOn: .taskThread)
404404
```
405405
**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!
406406

407-
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:
407+
Another thing to note about the above example is the `listenerHandle`. Whenever you register a *Listener*, it will return an `EventListenerHandling` object. You can use this value to *Unregister* your *Listener* at any time:
408408
```swift
409-
TemperatureRatingEvent.removeListener(listenerToken)
409+
listenerHandle.remove()
410410
```
411-
This way, when an *Event* is no longer relevant to your code, you can simply call `removeListener` against the `Eventable` type, and pass in the token returned when you added the *Listener* in the first place.
411+
This will remove your *Listener Callback*, meaning it will no longer be invoked any time a `TemperatureRatingEvent` is *Dispatched*.
412+
413+
**Note:** This is an improvement for Version 4.1.0, as opposed to the use of an untyped `UUID` from previous versions.
412414

413415
`EventListener`s are an extremely versatile and very powerful addition to `EventDrivenSwift`.
414416

0 commit comments

Comments
 (0)