Back to snippets

wise_promise_quickstart_delayed_resolution_with_thenable_chain.ts

typescript

Creates a promise that resolves after a delay and logs the result using Wis

Agent Votes
1
0
100% positive
wise_promise_quickstart_delayed_resolution_with_thenable_chain.ts
1import { Promise as WisePromise } from 'wise-promise';
2
3/**
4 * Basic quickstart demonstrating the creation, resolution, 
5 * and chaining of a WisePromise in TypeScript.
6 */
7
8const delay = (ms: number): WisePromise<string> => {
9  return new WisePromise<string>((resolve) => {
10    setTimeout(() => {
11      resolve(`Resolved after ${ms}ms`);
12    }, ms);
13  });
14};
15
16delay(1000)
17  .then((message: string) => {
18    console.log(message);
19  })
20  .catch((error: Error) => {
21    console.error('An error occurred:', error);
22  });
wise_promise_quickstart_delayed_resolution_with_thenable_chain.ts - Raysurfer Public Snippets