Constructor
# new Delayer(triggerTime)
Constructs a new Delayer
by specifying its trigger time.
Name | Type | Description |
---|---|---|
triggerTime |
number | The trigger time. |
- Source:
import { Delayer, asyncRoot } from 'modern-async'
asyncRoot(async () => {
const delayer = new Delayer(10) // a delayer with 10ms trigger time
// some cpu intensive operation that will run for a long time
for (let i = 0; i < 100000000; i += 1) {
// some code
await delayer.checkDelay()
}
})
Members
# triggerTime :number
The trigger time of this Delayer
in milliseconds. The trigger time represent the
maximum amount of time before a call to checkDelay()
decide to schedule a new task in the event loop.
- number
- Source:
Methods
# (async) checkDelay() → {boolean}
Checks if a delay must be applied according to the internal timer. If that's the case this method
will call delay()
and return true
. If not it will do nothing and return false
.
- Source:
true
if a new task was scheduled in the event loop, false
otherwise.
- Type
- boolean
# reset()
Resets the internal timer to the current time.
- Source: