npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

true-timeout

v1.0.0

Published

True Timeout is a Web Worker based utility that gives you the ability to have a timeout that is closest to a True Timeout unlike setTimeout (provided by the browser) that is based on the event loop.

Downloads

15

Readme

True Timeout

True Timeout is a Web Worker based utility that gives you the ability to have a timeout that is closest to a True Timeout unlike setTimeout (provided by the browser) that is based on the event loop.

An example can be seen here: https://revanth0212.github.io/true-timeout/

To start using it in your projects,

npm install true-timeout

Motivation

In languages like Java it is possible to have a timeout that is closer to a True Timeout, but when it comes to JavaScript that works on a single thread, true timeout is never achieved.

Current API that does timeout in JavaScript is setTimeout which is provided by the broswer. When you call setTimeout with a callback function and a timeout mentioned in milliseconds, the browser initiates a browser thread that will run the timeout logic and once done, puts the callback function in the JavaScript event loop.

Since the JavaScript engine is single threaded it can only run functions from a single stack. To implement timeout kind of Async operations, JavaScript engine picks up operations form event loop when ever it had nothing to do meaning the stack is empty.

So now setTimeout is dependent on event loop and hence it can only guarantee minimum timeout and not exact timeout.

For instance:

If we run the following in browser, a browser thread will be spawned and it will wait till 3 seconds after which it will put the alert call into the event loop.

setTimeout(function(){ alert("Hello"); }, 3000);

If the event loop already has some events pending, the alert call will stay there till the stack is empty and till all the pending events are addressed.

Solution: trueTimeout

Solution to this is a Worker based solution. True timeout works on a web worker which is also a thread by itself but it does not depend on the event loop.

Usage

window.trueTimeout(trueTimeoutCallBack, timeout, failureHandler)

trueTimeout is injected into global scope so you can start using it just like you would use setTimeout.

failureHandler is optional.

Params

  1. callback function which will be called once the timeout expires. Required. () => void
  2. timeout in milliseconds. Required. number
  3. errorHandler funciton which will be called if there is any error encountered in the whole process. Optional. () => void

Sample

Check out index.html

# Wanna Contribute?

Please fork/branch the project in github and once done create a PR.

To run the project locally for development make sure you have http-server package installed globally.

npm run start