Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/goto-bus-stop/raf-iterator
requestAnimationFrame as an async iterator
https://github.com/goto-bus-stop/raf-iterator
Last synced: 27 days ago
JSON representation
requestAnimationFrame as an async iterator
- Host: GitHub
- URL: https://github.com/goto-bus-stop/raf-iterator
- Owner: goto-bus-stop
- License: other
- Created: 2018-10-16T11:48:16.000Z (about 6 years ago)
- Default Branch: default
- Last Pushed: 2023-05-31T04:59:19.000Z (over 1 year ago)
- Last Synced: 2024-10-05T16:26:57.547Z (about 1 month ago)
- Language: JavaScript
- Size: 13.7 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# raf-iterator
requestAnimationFrame as an async iterator
Async iterators are very new and work on these platforms (non exhaustive):
- Firefox 60+
- Chrome 68+
- Safari 12
- Node 10+[Install](#install) - [Usage](#usage) - [License: Apache-2.0](#license)
[![npm][npm-image]][npm-url]
[![travis][travis-image]][travis-url]
[![standard][standard-image]][standard-url][npm-image]: https://img.shields.io/npm/v/raf-iterator.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/raf-iterator
[travis-image]: https://img.shields.io/travis/com/goto-bus-stop/raf-iterator.svg?style=flat-square
[travis-url]: https://travis-ci.com/goto-bus-stop/raf-iterator
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square
[standard-url]: http://npm.im/standard## Install
```
npm install raf-iterator
```## Usage
```js
const rafIterator = require('raf-iterator')for await (const tick of rafIterator()) {
draw(tick)
if (ended) {
break
}
}
```## API
### `rafIterator()`
Returns an Async Iterator that can be used in a `for await` loop. Each iteration yields an incrementing `tick` integer. Iterations occur at the speed of `requestAnimationFrame` ticks, about 60fps.
`break`ing from the loop prevents further animation frame requests.
## License
[Apache-2.0](LICENSE.md)