imccyu 6af96785b5 release(vendor): cordis 4.0.2, cosmokit 1.8.3, group 1.0.2, hmr 1.0.17, include 1.0.7, loader 1.0.3, logger-console 1.0.2, schemastery 3.18.2, timer 1.1.4 1 неделя назад
..
src ec601ca13d build(vendor): rescope the vendored Cordis packages into @deepseek-ai 3 недель назад
LICENSE 72688a3888 Vendor Cordis framework packages as source 2 месяцев назад
README.md 72688a3888 Vendor Cordis framework packages as source 2 месяцев назад
package.json 6af96785b5 release(vendor): cordis 4.0.2, cosmokit 1.8.3, group 1.0.2, hmr 1.0.17, include 1.0.7, loader 1.0.3, logger-console 1.0.2, schemastery 3.18.2, timer 1.1.4 1 неделя назад
tsconfig.json 7f131dd4d8 refactor: rename build typings dir to types 2 месяцев назад

README.md

@cordisjs/plugin-timer

Disposal-aware timer service for Cordis.

Usage

import { Context } from 'cordis'
import Timer from '@cordisjs/plugin-timer'

const root = new Context()
await root.plugin(Timer)

const dispose = root.timeout(() => {
  root.logger.info('done')
}, 1000)

dispose()

Timer handles are registered on the current fiber, so they are cleared automatically when the plugin that created them is disposed.

API

API Description
ctx.timeout(callback, delay) Run once and return a disposer.
ctx.timeout(delay) Return a promise that resolves after delay.
ctx.interval(callback, delay) Run repeatedly and return a disposer.
ctx.interval(delay) Return an async iterator that yields on each interval.
ctx.throttle(callback, delay, noTrailing?) Return a throttled function with .dispose().
ctx.debounce(callback, delay) Return a debounced function with .dispose().

ctx.setTimeout() and ctx.setInterval() are kept as deprecated aliases for ctx.timeout() and ctx.interval().