Last active
December 17, 2023 00:07
-
-
Save ahmedalejo/1ecec90c724e3e5746121e6574885099 to your computer and use it in GitHub Desktop.
Simple Typescript Task.delay(...) analogous to C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A class that provides ways for working with async code | |
* ```ts | |
* import { Task } from 'task' | |
* await Task.delay(1000); | |
* ``` | |
*/ | |
export class Task { | |
/** | |
* Creates a Task that will be completed after a time delay. | |
* @param {number} millisecondsDelay - The number of milliseconds to wait before resolving the returned Promise. | |
* @returns {Promise<void>} This is the result | |
*/ | |
private static delay(millisecondsDelay: number) { | |
return new Promise(resolve => setTimeout(resolve, millisecondsDelay)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice