Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ancss/itor
Using `for of` syntax iterator instance, supports pause and start at any time
https://github.com/ancss/itor
Last synced: 6 days ago
JSON representation
Using `for of` syntax iterator instance, supports pause and start at any time
- Host: GitHub
- URL: https://github.com/ancss/itor
- Owner: Ancss
- License: mit
- Created: 2022-01-12T15:02:56.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-01-13T15:38:17.000Z (about 3 years ago)
- Last Synced: 2024-04-28T17:46:41.430Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Itor
Using `for of` syntax iterator instance, supports pause and start at any time使用`for of`语法迭代实例,支持随时暂停和启动
## Install
```shell
# npm
$ npm install itor# deno
import {createItor} from "https://deno.land/x/itor/index.js";
```## Usage
```js
import Itor, { createItor } from 'itor'var lights = [
{
color: 'red',
time: 3000
},
{
color: 'yellow',
time: 1000
},
{
color: 'green',
time: 3000
},
];
var ls = createItor(lights) // || new Itor(lights)
for await (let value of ls) {
console.log(value.color)//loop:red=>yellow=>green
await new Promise((resolve, reject) => {
setTimeout(() => {
resolve()
}, value.time)
})
}
```## API
### createItor(values)
returns an itorable instance返回一个可迭代的实例
#### pause()
Pause the instance being itorated暂停迭代
#### play()
Play the instance being itorated继续迭代
#### stop()
Stop itorating over the current instance停止迭代