@abernier/loop

♻️

Usage no npm install needed!

<script type="module">
  import abernierLoop from 'https://cdn.skypack.dev/@abernier/loop';
</script>

README

NPM version

INSTALL

import Loop from 'https://unpkg.com/@abernier/loop@1.0.0'

Usage

At max speed (requestAnimationFrame):

const myLoop = new Loop((t1, t0) => {
  console.log(`dt: ${t1 - t0}`)
})

myLoop.start()

// ...

myLoop.stop()

At given speed (setTimeout):

const myLoop = new Loop((t1, t0) => {
  console.log(`dt: ${t1 - t0}`)
}, 1000)

myLoop.start()

// ...

myLoop.stop()