Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/stater/repeat

A simple promise based function repeater.
https://github.com/stater/repeat

loop repeat repeatr

Last synced: 13 days ago
JSON representation

A simple promise based function repeater.

Awesome Lists containing this project

README

        

A simple promise based function repeater.

**Example**

```typescript
import { repeat } from '@stater/repeat';

// Repeat console log 10 times.
repeat(console.log).repeat(10);

// Repeat console log until finished = true.
let finished = false;
repeat(rt => {
console.log(rt);

if (rt >= 10) {
finished = true;
}
}).every('5s').until(() => finished);

// Run maintenance checker every 5s.
let complete = false;
await repeat(async (rt) => {
console.log(`[Retries: ${rt}] Checking maintenance state.`);
complete = await server.checkMaintenance();
}).every('5s').until(complete);
console.log('Server maintenance completed!');
```