/** * A simple utility class for converting durations between minutes, seconds, and milliseconds. */ export declare class Duration { /** * The number of milliseconds in one second. */ static readonly MILLIS_IN_SECONDS: number; /** * The number of seconds in one minute. */ static readonly SECONDS_IN_MINUTE: number; /** * The number of minutes in one hour. */ static readonly MINUTES_IN_HOUR: number; /** * The number of hours in one day. */ static readonly HOURS_IN_DAY: number; /** * The number of days in one week. */ static readonly DAYS_IN_WEEK: number; readonly quantity: number; readonly unit: Duration.Unit; constructor(quantity: number, unit?: Duration.Unit); /** * Returns a new `Duration` instance created from the specified number of milliseconds. * * @param quantity The number of milliseconds. */ static milliseconds(quantity: number): Duration; /** * Returns a new `Duration` instance created from the specified number of seconds. * * @param quantity The number of seconds. */ static seconds(quantity: number): Duration; /** * Returns a new `Duration` instance created from the specified number of minutes. * * @param quantity The number of minutes. */ static minutes(quantity: number): Duration; /** * Returns a new `Duration` instance created from the specified number of hours. * * @param quantity The number of hours. */ static hours(quantity: number): Duration; /** * Returns a new `Duration` instance created from the specified number of days. * * @param quantity The number of days. */ static days(quantity: number): Duration; /** * Returns a new `Duration` instance created from the specified number of weeks. * * @param quantity The number of weeks. */ static weeks(quantity: number): Duration; /** * Returns the current number of milliseconds represented by this `Duration` instance. */ get milliseconds(): number; /** * Returns the current number of seconds represented by this `Duration` instance, rounded to the nearest integer * value. */ get seconds(): number; /** * Returns the current number of minutes represented by this `Duration` instance, rounded to the nearest integer * value. */ get minutes(): number; /** * Returns the current number of hours represented by this `Duration` instance. */ get hours(): number; /** * Returns the current number of days represented by this `Duration` instance. */ get days(): number; /** * Returns the current number of weeks represented by this `Duration` instance. */ get weeks(): number; /** * The string representation of this `Duration`. e.g. "645 seconds" */ toString(): string; private pluralize; } export declare namespace Duration { /** * Units of duration. */ enum Unit { MINUTES = 0, MILLISECONDS = 1, SECONDS = 2, HOURS = 3, DAYS = 4, WEEKS = 5 } } /** * An abstraction for any interruptable operation. */ export interface Interruptable { interrupt: () => void; } /** * A promise of result type `T` that can be interrupted prematurely, resulting in an early resolution. */ export declare type InterruptablePromise = Promise & Interruptable; /** * Sleeps for a given `Duration`. This is essentially a promisified version of `setTimeout`. May be interrupted * by calling `interrupt()` on the returned `InterruptablePromise`. * * @param duration The duration to wait. * * ``` * // sleep 5 seconds * await sleep(Duration.seconds(5)); * * // sleep 10 minutes unless interrupted by an event * const promise = sleep(Duration.minutes(10)); * events.on('someEvent', promise.interrupt); * await promise; * ``` */ export declare function sleep(duration: Duration): InterruptablePromise; /** * Sleeps for a given duration, with units defaulting to milliseconds. This is essentially a promisified version * of `setTimeout`. May be interrupted by calling `interrupt()` on the returned `InterruptablePromise`. * * @param quantity The quantity of duration to wait. * @param unit The `Duration.Unit` in which quantity is specified, defaulting to milliseconds. * * ``` * // sleep 5 seconds * await sleep(5000); * * // sleep 10 minutes unless interrupted by an event * const promise = sleep(10, Duration.Unit.MINUTES); * events.on('someEvent', promise.interrupt); * await promise; * ``` */ export declare function sleep(quantity: number, unit?: Duration.Unit): InterruptablePromise;