Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jacobbubu/looper
https://github.com/jacobbubu/looper
Last synced: 15 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/jacobbubu/looper
- Owner: jacobbubu
- License: mit
- Created: 2020-05-12T13:44:26.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T05:42:01.000Z (about 2 years ago)
- Last Synced: 2025-01-05T00:07:02.397Z (23 days ago)
- Language: TypeScript
- Homepage:
- Size: 1.15 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# @jacobbubu/looper
[![Build Status](https://github.com/jacobbubu/looper/workflows/Build%20and%20Release/badge.svg)](https://github.com/jacobbubu/looper/actions?query=workflow%3A%22Build+and+Release%22)
[![Coverage Status](https://coveralls.io/repos/github/jacobbubu/looper/badge.svg)](https://coveralls.io/github/jacobbubu/looper)
[![npm](https://img.shields.io/npm/v/@jacobbubu/looper.svg)](https://www.npmjs.com/package/@jacobbubu/looper/)> Rewritten [looper](https://github.com/dominictarr/looper) in TypeScript.
## Synopsis
Normally, if `mightBeAsync` calls it's cb immediately
this would `RangeError`:``` js
let l = 100000
;(function next () {
if(--l) mightBeAsync(next)
})
````looper` detects that case, and falls back to a `while` loop,
in computer science something like this is called a [trampoline](https://en.wikipedia.org/wiki/Trampoline_(computing))
this module is simpler than other trampoline libraries such as [tail-call](https://github.com/Gozala/js-tail-call)
because it does not preserve arguments. But this is still useful
for looping when async recursion is sometimes sync.This is about 10 times faster than using [setImmediate](http://devdocs.io/node~6_lts/timers#timers_setimmediate_callback_args)
## Example
``` js
import looper from 'looper'let l = 100000
const next = looper(function () {
if(--l) probablySync(next)
})next()
```when you want to stop looping, don't call `next`.
`looper` checks if each callback is sync or not,
so you can even mix sync and async calls!## License
MIT