Created
May 28, 2024 11:59
-
-
Save omarmosid/067d356bc88a48d383f53d72a1f401c9 to your computer and use it in GitHub Desktop.
mock api call
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
| // Define the async function with TypeScript | |
| async function mockApiCall(delay: number): Promise<string> { | |
| return new Promise((resolve) => { | |
| setTimeout(() => { | |
| resolve('Mock API call completed'); | |
| }, delay); | |
| }); | |
| } | |
| // Example usage | |
| (async () => { | |
| console.log('Calling mock API...'); | |
| const result = await mockApiCall(2000); // Simulate a 2-second API call | |
| console.log(result); // Output: Mock API call completed | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment