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
- Typo corrected in `EventPool` which would make the number of `EventThread`s in the pool always one more than requested for the capacity.
- Updated README.MD for Version 4.0.0
@@ -412,11 +412,37 @@ This way, when an *Event* is no longer relevant to your code, you can simply cal
412
412
413
413
`EventListener`s are an extremely versatile and very powerful addition to `EventDrivenSwift`.
414
414
415
+
## `EventPool`
416
+
Version 4.0.0 introduces the extremely powerful `EventPool` solution, making it possible to create managed groups of `EventThread`s, where inbound *Events* will be directed to the best `EventThread` in the `EventPool` at any given moment.
417
+
418
+
`EventDrivenSwift` makes it trivial to produce an `EventPool` for any given `EventThread` type.
419
+
420
+
To create an `EventPool` of our `TemperatureProcessor` example from earlier, we can use a single line of code:
421
+
```swift
422
+
var temperatureProcessorPool = EventPool<TemperatureProcessor>(capacity: 5)
423
+
```
424
+
The above example will create an `EventPool` of `TemperatureProcessor`s, with an initial *Capacity* of **5** instances. This means that your program can concurrently process **5**`TemperatureEvent`s.
425
+
Obviously, for a process so simple and quick to complete as our earlier example, it would not be neccessary to produce an `EventPool`, but you can adapt this example for your own, more complex and time-consuming, `EventThread` implementations to immediately parallelise them.
426
+
427
+
`EventPool`s enable you to specify the most context-appropriate *Balancer* on initialization:
428
+
```swift
429
+
var temperatureProcessorPool = EventPool<TemperatureProcessor>(capacity: 5, balancer: EventPoolRoundRobinBalancer())
430
+
```
431
+
The above example would use the `EventPoolRoundRobinBalancer` implementation, which simply directs each inbound `Eventable` to the next `EventThread` in the pool, rolling back around to the first after using the final `EventThread` in the pool.
432
+
433
+
There is also another *Balancer* available in version 4.0.0:
434
+
```swift
435
+
var temperatureProcessorPool = EventPool<TemperatureProcessor>(capacity: 5, balancer: EventPoolLowestLoadBalancer())
436
+
```
437
+
The above example would use the `EventPoolLowestLoadBalancer` implementation, which simply directs each inbound `Eventable` to the `EventThread` in the pool with the lowest number of pending `Eventable`s in its own *Queue* and *Stack*.
438
+
439
+
**NOTE:** When no `balancer` is declared, `EventPool` will use `EventPoolRoundRobinBalancer` by default.
440
+
415
441
## Features Coming Soon
416
442
`EventDrivenSwift` is an evolving and ever-improving Library, so here is a list of the features you can expect in future releases:
417
-
-**Event Pools** - A superset expanding upon a given `EventThread` descendant type to provide pooled processing based on given scaling rules and conditions.
443
+
-**Event Pool Scalers** - Dynamic Scaling for `EventPool` instances will be fully-implemented
418
444
419
-
These are the features intended for the next Release, which will either be *3.2.0* or *4.0.0* depending on whether these additions require interface-breaking changes to the interfaces in version *3.1.0*.
445
+
These are the features intended for the next Release, which will either be *4.1.0* or *5.0.0* depending on whether these additions require interface-breaking changes to the interfaces in version *4.0.0*.
0 commit comments