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

zthreader

v2.0.1

Published

JavaScript library that provides pseudo-threading for leveraging resources during long, CPU intensive operations

Downloads

667

Readme

zThreader

JavaScript "threading" library for maintaining application responsiveness during heavy operations!

Originally written in 2010 when JavaScript provided no "real" threading available and Workers only offered limited functionality as they operate "in their own space", separated from the remainder of your application, often without much needed browser API's.

To overcome this, zThreader has been created. A "zThread" is basically a class that can be extended / implemented to subdivide a processor-heavy operation into smaller iterations, which will be executed whenever the web browser has CPU resources available. In other words : you can enjoy the number crunching of your ultra cool heavy operation(s), while still keeping the user interface of your application responsive while the operation is running. Additionally, you can create Java / C-style "daemon" operations (the type that never finish and are running as an eternal "while"-loop, which would otherwise lock script execution when done in JavaScript), finally allowing you to create your awesome "eternally generating new Mandelbrots"-application!.

Granted, this form of "fake threading" takes longer to execute as opposed to running the operation in one go, but the benefits of keeping your application feel smooth and responsive PLUS overcoming the dreaded crash as script execution timeouts occur, should make you consider using this approach. Clever benchmarking of your custom operations can make the extra processing time actually negligible!

When in doubt, check the live demos below.

2022 update

Nowadays there are plenty of different ways to maintain application performance while running computation heavy operations. Consider using Web Workers and/or WebAssembly for your applications. More and more API's overcome restrictions / provide alternatives to Window API's or shared memory usage.

If you however need to tweak a legacy application or require browser API's unavailable to Workers or don't want to introduce post messaging overhead, you can reach for zThreader to provide a quick solution to unresponsive pages being killed by the browser.

Installation

You can get zThreader via NPM:

npm install zthreader

Project Integration

zThreader is compatible with ES modules, AMD/RequireJS or can be included in the browser via script tags. zThreader is written in TypeScript and comes with type annotations.

ES module:

import { zThreader, zThread } from "zthreader";

RequireJS:

require( [ "zThreader", "zThread" ], ( zThreader, zThread ) => {
    // do something...
});

Browser:

<script type="text/javascript" src="./dist/zthreader.min.js"></script>

Dependencies

zThreader requires no other JavaScript libraries and thus can be used within any context. There is no super secret stuff going on either, so it should work on pretty much anything including Internet Explorer 6 (!). Having said that, to leverage CPU consumption, zThreader uses requestAnimationFrame. If your project is to support older browsers without this feature, you can easily use a shim / polyfill for requestAnimationFrame and still use zThreader.

But if you don't care about IE9 or lower you can rejoice as this will run out of the box.

Documentation

Want to view the API ? You can check the wiki here : https://github.com/igorski/zThreader/wiki/zThreader-overview

LIVE DEMOS

Demo 1:

Here we run twos daemon-style thread and observe neither is blocking the remainder of the application.

https://rawgithub.com/igorski/zThreader/master/examples/demo1.html

Demo 2:

Here you can view and compare the zThreader with a non-threaded execution, and even test multiple instances of zThreaded operations running at the same time, while maintaining a responsive UI throughout!

https://rawgithub.com/igorski/zThreader/master/examples/demo2.html