Skip to content

Instantly share code, notes, and snippets.

@ahmedalejo
Last active December 17, 2023 00:07
Show Gist options
  • Save ahmedalejo/1ecec90c724e3e5746121e6574885099 to your computer and use it in GitHub Desktop.
Save ahmedalejo/1ecec90c724e3e5746121e6574885099 to your computer and use it in GitHub Desktop.
Simple Typescript Task.delay(...) analogous to C#
/**
* 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));
}
}
@ColonelFPS
Copy link

Nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment