Skip to content

Commit

Permalink
docs: update readme
Browse files Browse the repository at this point in the history
Updates readme to include section on versioning.
  • Loading branch information
kleinfreund committed Aug 16, 2021
1 parent 1cd4b79 commit aa6fb29
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ Links:



## Table of contents
## Contents

- [Installation](#installation)
- [Tests](#tests)
- [Documentation](#documentation)
- [Examples](#examples)
- [Versioning](#versioning)



Expand Down Expand Up @@ -75,19 +75,6 @@ npm install poll
poll(fn, 1000)
```



## Tests

In order to run the tests, clone the repository and run the following commands:

```sh
npm install
npm test
```



## Documentation

### Syntax
Expand All @@ -98,22 +85,20 @@ poll(function, delay[, shouldStopPolling])

**Parameters**:

- **function**: Required. A function to be called every `delay` milliseconds. No parameters are passed to `function` upon calling it.
- **fn**: Required. A function to be called every `delay` milliseconds. No parameters are passed to `fn` upon calling it.
- **delay**: Required. The delay (in milliseconds) to wait before calling the function again. If `delay` is negative, zero will be used instead.
- **shouldStopPolling**: Optional. A function indicating whether to stop the polling process. The callback function is evaluated twice during one iteration of the internal loop:
- After the result of the call to `function` was successfully awaited. In other words, right before triggering a new delay period.
- After the `delay` has passed. In other words, right before calling `function` again.
- After the result of the call to `fn` was successfully awaited. In other words, right before triggering a new delay period.
- After the `delay` has passed. In other words, right before calling `fn` again.

This guarantees two things:
- A currently active execution of `function` will be completed.
- No new calls to `function` will be triggered.
- A currently active execution of `fn` will be completed.
- No new calls to `fn` will be triggered.

**Return value**:

None.



## Examples

The `poll` function expects two parameters: A callback function and a delay. After calling `poll` with these parameters, the callback function will be called. After it’s done being executed, the `poll` function will wait for the specified `delay`. After the delay, the process starts from the beginning.
Expand All @@ -122,7 +107,7 @@ The `poll` function expects two parameters: A callback function and a delay. Aft
const pollDelayInMinutes = 10

async function getStatusUpdates() {
const response = await fetch('/status')
const response = await fetch('/api/status')
console.log(response)
}

Expand Down Expand Up @@ -151,3 +136,7 @@ setTimeout(() => {

poll(fn, 50, shouldStopPolling)
```

## Versioning

This package uses [semantic versioning](https://semver.org).

0 comments on commit aa6fb29

Please sign in to comment.