-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial implementation of poll function
- Loading branch information
0 parents
commit 49d5bc9
Showing
7 changed files
with
6,357 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# poll | ||
|
||
A simple poll function based on async, await, and an infinite loop. | ||
|
||
|
||
|
||
## Table of contents | ||
|
||
- [Installation](#installation) | ||
- [Tests](#tests) | ||
- [Documentation](#documentation) | ||
- [Usage](#usage) | ||
|
||
|
||
|
||
## Installation | ||
|
||
Install the NPM package as a dependency … | ||
|
||
```sh | ||
npm install --save poll | ||
``` | ||
|
||
… and import it like this: | ||
|
||
```node | ||
const poll = require('poll'); | ||
|
||
function fn() { | ||
console.log('Hello, beautiful!'); | ||
}; | ||
|
||
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 | ||
|
||
``` | ||
poll(function, delay[, shouldStopPolling]) | ||
``` | ||
|
||
**Parameters**: | ||
|
||
- **function**: Required. A function to be called every `delay` milliseconds. No parameters are passed to `function` upon calling it. | ||
- **delay**: Required. The delay (in milliseconds) to wait before calling the function again. | ||
- **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. | ||
|
||
This guarantees two things: | ||
- A currently active execution of `function` will be completed. | ||
- No new calls to `function` will be triggered. | ||
|
||
**Return value**: | ||
|
||
None. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) Philipp Rudloff | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
Oops, something went wrong.