UNPKG

@itwin/core-bentley

Version:

Bentley JavaScript core components

123 lines 5.75 kB
/** @packageDocumentation * @module Utils */ /** A duration of time. Can be either positive (towards future) or negative (in the past). * BeDurations are immutable. * @public */ export declare class BeDuration { private readonly _milliseconds; private constructor(); /** The duration in milliseconds */ get milliseconds(): number; get seconds(): number; /** Create a BeDuration from seconds. * @param seconds the number of seconds for this BeDuration */ static fromSeconds(seconds: number): BeDuration; /** Create a BeDuration from milliseconds. * @param milliseconds the number of milliseconds for this BeDuration */ static fromMilliseconds(milliseconds: number): BeDuration; /** Determine whether this BeDuration is 0 seconds */ get isZero(): boolean; /** Determine whether this BeDuration is towards the future */ get isTowardsFuture(): boolean; /** Determine whether this BeDuration is towards the past */ get isTowardsPast(): boolean; /** Subtract a BeDuration from this BeDuration, returning a new BeDuration. */ minus(other: BeDuration): BeDuration; /** Add a BeDuration to this BeDuration, returning a new BeDuration */ plus(other: BeDuration): BeDuration; /** Utility function to just wait for the specified time * @param ms Duration in milliseconds to wait * @return Promise that resolves after the specified wait period */ static wait(ms: number): Promise<void>; /** Utility function to wait for either the specified time or a promise, whichever resolves first * @param ms Maximum duration in milliseconds to wait * @param promise A pending promise to wait for * @return Promise that resolves after the specified wait period or the provided promise resolves, whichever comes first */ static race<T>(ms: number, promise: PromiseLike<T>): Promise<T | void>; /** Utility function to just wait for the specified time * @return Promise that resolves after the specified wait period */ wait(): Promise<void>; /** Execute a function after delaying by this duration. * @param fn the function to execute after the delay * @param scope An optional object scope to serve as the 'this' pointer when `fn` is invoked. * @param args optional arguments to `fn` * @return Promise resolved by `fn` */ executeAfter<T>(fn: (...args: any[]) => T, scope?: any, ...args: any[]): Promise<T>; } /** A specific point in time relative to the current time. * BeTimePoints are used for timing operations. They are created from a BeDuration relative to the "now". * BeTimePoints are immutable. * @public */ export declare class BeTimePoint { private readonly _milliseconds; /** the time in milliseconds, of this BeTimePoint (relative to January 1, 1970 00:00:00 UTC.) */ get milliseconds(): number; private constructor(); /** Create a BeTimePoint from Date.now() */ static now(): BeTimePoint; /** Create a BeTimePoint at a specified duration in the future from now * @param val the duration from now */ static fromNow(val: BeDuration): BeTimePoint; /** Create a BeTimePoint at a specified duration in the past before now * @param val the duration before now */ static beforeNow(val: BeDuration): BeTimePoint; /** Determine whether this BeTimePoint is a time in the future from the time this method is called (it calls now()!) */ get isInFuture(): boolean; /** Determine whether this BeTimePoint is a time that has already passed before the time this method is called (it calls now()!) */ get isInPast(): boolean; /** Determine whether this BeTimePoint happens before another one. * @param other the other BeTimePoint. */ before(other: BeTimePoint): boolean; /** Determine whether this BeTimePoint happens after another one. * @param other the other BeTimePoint. */ after(other: BeTimePoint): boolean; /** Subtract a BeDuration from this BeTimePoint, returning a new BeTimePoint. This moves this BeTimePoint backwards in time if BeDuration.isTowardsFuture() === true * @param duration the duration to subtract. */ minus(duration: BeDuration): BeTimePoint; /** Subtract a BeDuration from this BeTimePoint, returning a new BeTimePoint. This moves this BeTimePoint backwards in time if BeDuration.isTowardsFuture() === true * @param duration the duration to subtract. */ plus(duration: BeDuration): BeTimePoint; } /** A StopWatch for timing operations. * @public */ export declare class StopWatch { description?: string | undefined; private _start?; private _stop?; /** Get the elapsed time since start() on a running timer. */ get current(): BeDuration; /** Get the elapsed time, in seconds, since start() on a running timer. */ get currentSeconds(): number; /** Get the elapsed time between start() and stop() on this timer in milliseconds. */ get elapsed(): BeDuration; /** Get the elapsed time, in seconds, between start() and stop() on this timer. */ get elapsedSeconds(): number; /** ctor for StopWatch * @param description optional string stored with the StopWatch * @param startImmediately if true, StopWatch is started when created. Otherwise, call start() explicitly. */ constructor(description?: string | undefined, startImmediately?: boolean); /** Start the stopwatch. Any future time measurements will be based on this new value. */ start(): void; /** Stop the stopwatch so that the duration can be viewed later. */ stop(): BeDuration; /** Clear the StopWatch */ reset(): void; } //# sourceMappingURL=Time.d.ts.map