Skip to content

Commit

Permalink
release: bump to 0.3.0 & update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mslalith committed Jun 5, 2022
1 parent 6519bec commit 3eaecad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
37 changes: 13 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,33 @@ Poller is a simple Kotlin library which runs a certain task at a regular interva

## Download
```kotlin
implementation("dev.mslalith:poller:0.2.0")
implementation("dev.mslalith:poller:0.3.0")
```

## Usage

### Create Poller

An instance to Poller can be created in two ways:
Use `Poller.new` method to create new Poller. This takes<br>

- Use `Poller.indefinite` method to run the forever until stopped explicitly
```kotlin
val poller: Poller<Int> = Poller.indefinite(
coroutineScope = coroutineScope,
pollInterval = 1_000
)
```

- Use `Poller.create` method to create new Poller. This takes<br>

`coroutineScope` - The scope in which the poll should execute<br>
`pollInterval` - Time in millis for the next poll to execute after<br>
`pollRepeatCount` - Number of times for the poll to execute<br>
`maxRetries` - Maximum number of times the poll can retry within the poll lifecycle

For example, let's take `pollInterval = 4_000` and `pollRepeatCount = 5`<br>
Then the total time of this poll would be `20_000 (4_000 * 5)`

Poll will be stopped if retries are exhausted or its lifetime expires.
`coroutineScope` - The scope in which the poll should execute<br>
`pollInterval` - Time in millis between each poll<br>
`pollStrategy` - The strategy for the poll to continue

```kotlin
val poller: Poller<Int> = Poller.finite(
val poller: Poller<Int> = Poller.new(
coroutineScope = coroutineScope,
pollInterval = 1_000,
pollRepeatCount = 4,
maxRetries = 2
pollStrategy = IndefiniteStrategy()
)
```

### Poll Strategies

- `IndefiniteStrategy` - runs indefinitely
- `RetryLimitStrategy` - stop when retires are exhausted
- `TimeoutStrategy` - stop when time is exhausted

### Consuming Poll events

Poller exposes a `StateFlow<PollerState>` which holds the current state of your Poll.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "dev.mslalith"
version = "0.3.0-alpha01"
version = "0.3.0"

repositories {
mavenCentral()
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/dev/mslalith/poller/Poller.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ fun <T> Poller<T>.stopIfPolling() {
* Create a new Poller instance
*
* @param coroutineScope The scope in which the poll should execute
* @param pollInterval Time in millis for the poll to run after
* @param pollStrategy The strategy to continue the poll
* @param pollInterval Time in millis between each poll
* @param pollStrategy The strategy for the poll to continue
*/
fun <T> Poller.Companion.new(
coroutineScope: CoroutineScope,
Expand Down

0 comments on commit 3eaecad

Please sign in to comment.