mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 08:23:12 +09:00
Add time unit suffixes to variables (#561)
Add suffixes like Ms and Ns to variables whos time unit is not in seconds. This is aligning with a new code style of putting units on variables that are not in SI base units.
This commit is contained in:
1 parent
9842705eb9
commit
c53781d16c
38 files changed
+221
-201
No files matched your search
@@ -22,10 +22,10 @@ export function basicType(value: unknown) {
|
||||
/**
|
||||
* Asynchronously wait for the given duration
|
||||
*
|
||||
* @param duration - Time to wait for in milliseconds.
|
||||
* @param durationMs - Time to wait for in milliseconds.
|
||||
*/
|
||||
export async function wait(duration: number) {
|
||||
await new Promise(resolve => { setTimeout(resolve, duration); });
|
||||
export async function wait(durationMs: number) {
|
||||
await new Promise(resolve => { setTimeout(resolve, durationMs); });
|
||||
}
|
||||
|
||||
|
||||
@@ -33,16 +33,16 @@ export async function wait(duration: number) {
|
||||
* Resolve a promise with a timeout.
|
||||
*
|
||||
* @param {Promise} promise - Promise to wait for.
|
||||
* @param {number} time - Maximum time im milliseconds to wait for.
|
||||
* @param {number} limitMs - Maximum time im milliseconds to wait for.
|
||||
* @param {*=} timeoutResult - Value to return if the operation timed out.
|
||||
*/
|
||||
export async function timeout<T>(promise: Promise<T>, time: number, timeoutResult: T) {
|
||||
export async function timeout<T>(promise: Promise<T>, limitMs: number, timeoutResult: T) {
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
try {
|
||||
return await Promise.race([
|
||||
promise,
|
||||
new Promise<T>(resolve => {
|
||||
timer = setTimeout(() => resolve(timeoutResult), time);
|
||||
timer = setTimeout(() => resolve(timeoutResult), limitMs);
|
||||
}),
|
||||
]);
|
||||
|
||||
|
||||
Reference in new issue
Block a user