Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
pomponchik committed Jul 23, 2024
1 parent 970ea82 commit 26c2dbc
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This library offers the easiest way to run regular tasks. Just give it a functio
- [**Logging**](#logging)
- [**Error escaping**](#error-escaping)
- [**Working with Cancellation Tokens**](#working-with-cancellation-tokens)
- [**Limitations**](#limitations)
- [**How to set a time limit**](#how-to-set-a-time-limit)


## Quick start
Expand Down Expand Up @@ -247,19 +247,32 @@ metronome.start(token=TimeoutToken(1))
If you pass cancellation tokens both during metronome initialization and in the `start()` method, their limitations will be summed up.


## Limitations
## How to set a time limit

You can limit the total running time of the metronome by setting the `duration` value (in seconds):
You can specify a time limit (in seconds) for which the metronome will tick. When the specified time is over, it will simply stop. There are 2 ways to do this: when creating a metronome object or when calling the `start()` method.

```python
from time import sleep
from metronomes import Metronome
In the first way, the time will start counting from the moment the metronome object is created:

metronome = Metronome(0.2, lambda: print('go!'), duration=0.6)
```python
metronome = Metronome(0.2, lambda: print('go!'), duration=0.6)

metronome.start()
sleep(1)
#> go!
#> go!
#> go!
```

In the second way, the countdown will start by calling the `start()` method:

```python
metronome = Metronome(0.2, lambda: print('go!'))

metronome.start(duration=0.6)
sleep(1)
#> go!
#> go!
#> go!
```

Choose the right way to limit time. When using the metronome in the [context manager mode](#use-it-as-a-context-manager), only the first way is available to you, in almost all other situations - the second one is preferable.

0 comments on commit 26c2dbc

Please sign in to comment.