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

awake.js

v1.0.0

Published

A class to delay a task and/or to control a task in a thread way, with start, stop, pause and resume.

Downloads

4

Readme

Awake.js

A class to delay a task and/or to control a task in a thread way, with start, stop, pause and resume.

A task cannot then run more than once at a time, to prevent concurency running.

Install

$ npm i awake.js

Class Awake

constructor

new Awake(function, [integer])

/**
 * @constructor
 * @param {function}    callback    The task.
 * @param {number}      delay       The delay before running the task.
 *                                  Sets 0 for a one shot task.
 * @throws {RequiredCallbackException}
 */
function Awake ( callback, delay )

Methods

delay()

    /**
     * Retrieve the delay for that task.
     * @method      delay
     * @memberof    Awake
     * @return      {number} The delay of the task.
     */
    function delay ()

isPaused()

    /**
     * Tell if the Awake instance is paused.
     * @method      isPaused
     * @memberof    Awake
     * @return      {boolean} True when paused, false otherwise.
     */
   function isPaused ()

isRunning()

    /**
     * Tell if the Awake instance is running.
     * @method      isRunning
     * @memberof    Awake
     * @return      {boolean} True when running, false otherwise.
     */
    function isRunning ()

pause()

    /**
     * Sets to pause the Awake instance.
     * @method      pause
     * @memberof    Awake
     * @returns     {void}
     */
    function pause ()

resume()

    /**
     * Resume a paused Awake's instance.
     * @method      resume
     * @memberof    Awake
     * @returns     {void}
     */
    function resume ()

start()

    /**
     * Start the task, according to the delay.
     * @method      start
     * @memberof    Awake
     * @returns     {void}
     */
    function start ()

stop()

    /**
     * Stop the running task.
     * @method      stop
     * @memberof    Awake
     * @returns     {void}
     */
    function stop ()

callback

   /**
    * The callback function.
    * @function
    * @param {function}    done  The function to call at the end of the loop.
    * @param {number}      time  The started timestamp of the loop.
    */
   function ( done, time )

Usage

const util = require('util');
const Awake = require('.');

let counter = 0;

const wake = new Awake( (done, time) => {
   console.log( util.format("I was called at %i, %i times", time, ++counter) );
   // do someting interesting...
   done();
   if ( counter === 10 ) wake.stop();
},500);

wake.start();

License

MIT © guitarneck