Skip to content

Instantly share code, notes, and snippets.

@omarmosid
Created May 28, 2024 11:59
Show Gist options
  • Select an option

  • Save omarmosid/067d356bc88a48d383f53d72a1f401c9 to your computer and use it in GitHub Desktop.

Select an option

Save omarmosid/067d356bc88a48d383f53d72a1f401c9 to your computer and use it in GitHub Desktop.
mock api call
// 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