🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@franckldx/ts-wait

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@franckldx/ts-wait

Helpers to wait for somethinf in javascript

1.0.3
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

ts-wait

I'm tired to write a wait function again and agin in my projects, so I make this simple project.

await wait(100) // wait 100 milliseconds

This lib does not do only this. Mainly it allows to set timetou on function, ethier synchronous or asynchronous:

 try {
   const func = ()=> {/* do something synchronous */},
   const result = await waitUntil(
     func,
     10000 // <- in milliseconds
   );
 } catch (err) {
   if (isTimeoutError(error)) { {
     // fn does not complete after 10 seconds
   } else {
     // fn throws an exception
   }
 }

It throws an error of type TimeoutError it timeout occurs. The isTimeoutError is a type guard to check is error is a TimeoutError.

To set a timeout on an async function

try {
  const result = await waitUntilAsync(async () => {
    /* do something */
  }, 10000);
} catch (err) {
  if (isTimeoutError(error)) {
    // fn does not complete after 10 seconds
  } else {
    // fn throws an exception
  }
}

Keywords

typescript

FAQs

Package last updated on 09 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts