Skip to content

Commit

Permalink
Update badges, docs. Refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyampo authored and sergeyampo committed Jan 20, 2023
1 parent d3a92bb commit 41e9b1e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![Workflow](https://github.com/sergeyampo/array-to-async-iterable/actions/workflows/npm-publish.yml/badge.svg)

# array-to-async-iterable
This tiny package with zero-dependencies, typescript .d.ts coverage, full ESM and CJS compatibility helps you to iterate over large collections in **Node.js** truly asynchronously.

Expand Down Expand Up @@ -55,4 +57,4 @@ It's recommended for an array to be large and have simple operations in a loop.
You won't get much profit using small arrays for extremely long operations.


Inspired by @metarhia.
Inspired by [@metarhia](https://github.com/HowProgrammingWorks).
4 changes: 4 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export declare class AsyncTimeIterator{
/**
* @param array Iterable contract.
* @param ms Give a quantum of time to the event loop every n milliseconds.
*/
constructor<T>(array: Array<T>, ms?: number);
}
5 changes: 3 additions & 2 deletions lib/async-time-iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ const DEFAULT_INTERVAL = 500;

class AsyncTimeIterator {
#arrayRef = [];
#interval;

constructor(array, ms = DEFAULT_INTERVAL) {
this.#arrayRef = array;
this._interval = ms;
this.#interval = ms;
}

[Symbol.asyncIterator]() {
let time = Date.now();
let i = 0;
const interval = this._interval;
const interval = this.#interval;
return {
next: () => {
const now = Date.now();
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
"type": "git",
"url": "git+https://github.com/sergeyampo/array-to-async-iterable.git"
},
"keywords": [
"array-to-async-iterable",
"for await array",
"async iterator array",
"AsyncIterable",
"AsyncTimeIterator",
"nodejs async array",
"nodejs async iterator",
"nodejs array to async iterable"
],
"author": "sergeyampo",
"license": "MIT",
"bugs": {
Expand Down

0 comments on commit 41e9b1e

Please sign in to comment.