Skip to content

Commit d76bb83

Browse files
committed
#24 Add the description to README about the new feature.
1 parent 90e0b63 commit d76bb83

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,38 @@ Channel.select(
284284
)
285285
```
286286

287+
#### Time.after()
288+
Like in Go, you can use `Time.after(duration)` to generate a channel that sends a message after the specified time has
289+
passed. You don't need to close the channel afterward.
290+
291+
```scala
292+
import com.github.yruslan.channel._
293+
294+
Channel.select(
295+
someChannel.recver{v => println(s"Got a message in time: $v")},
296+
Time.after(Duration(10, TimeUnit.SECONDS)).recver{ v => println("Time is out!") }
297+
)
298+
```
299+
300+
#### Time.newTicker()
301+
Like in Go, you can use `Time.newTicker(duration)` to generate a channel that sends a message after the specified time.
302+
When the message is consumed, the ticker will generate another message after the same time duration.
303+
Tickers should be closed after they are not in use.
304+
305+
```scala
306+
import com.github.yruslan.channel._
307+
308+
val ticker = Time.newTicker(Duration(10, TimeUnit.SECONDS))
309+
310+
Channel.select(
311+
someChannel.recver{v => println(s"Got a message: $v")},
312+
ticker.recver{ _ => println("Tick.") }
313+
)
314+
315+
ticker.close()
316+
```
317+
318+
287319
### Non-blocking methods
288320
Go supports non-blocking channel operation by the elegant `default` clause in the `select` statement. The scala port
289321
adds separate methods that support non-blocking operations: `trySend()`, `tryRecv()` and `trySelect()`. There is an

0 commit comments

Comments
 (0)