Skip to content

Commit e37dcda

Browse files
committed
Version 4.0.0
- 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
1 parent 9f47f17 commit e37dcda

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

README.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ let package = Package(
130130
dependencies: [
131131
.package(
132132
url: "https://github.com/Flowduino/EventDrivenSwift.git",
133-
.upToNextMajor(from: "3.1.0")
133+
.upToNextMajor(from: "4.0.0")
134134
),
135135
],
136136
//...
@@ -412,11 +412,37 @@ This way, when an *Event* is no longer relevant to your code, you can simply cal
412412

413413
`EventListener`s are an extremely versatile and very powerful addition to `EventDrivenSwift`.
414414

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+
415441
## Features Coming Soon
416442
`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
418444

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*.
420446

421447
## License
422448

Sources/EventDrivenSwift/EventPool/EventPool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ open class EventPool<TEventThread: EventThreadable>: EventHandler, EventPooling
157157
super.init()
158158
// Now we create all of our Event Threads
159159
var current = 0
160-
while current < capacity + 1 {
160+
while current < capacity {
161161
let eventThread = TEventThread(eventPool: self)
162162
eventThreads.append(eventThread)
163163
current += 1

0 commit comments

Comments
 (0)