Giter Site home page Giter Site logo

wait's Introduction

wait

Project unmaintained

Syntactic sugar for setTimeout and setInterval.

wait(time, callback, id)

Sugar for setTimeout.

wait(100, function(){
    // Do something in 100 milliseconds
});

wait('2s', function(){
    // Do something in 2 seconds
});

wait('2 minutes', function(){
    // Do something in 2 minutes
}, 'awesomeId');

repeat(time, callback, id, callBefore = false)

Sugar for setInterval.

If callBefore is true the callback will be executed before the interval.

repeat(100, function() {
    // Do something every 100 milliseconds
});

repeat('1 min', function() {
    // Do something every minute
}, 'awesomeId');

repeat('1 min', function() {
    // Run immediately and every minute
}, true);

repeat('1 min', function() {
    // Run immediately and every minute
}, 'awesomeId', true);

until(condition, callback, interval = 100, id)

Runs the callback function when the condition is true. If you don't specify an interval the condition will be check every 100 milliseconds.

var condition = function() {
    return 1 == 1;
};

until(condition, function() {
    // Do something when 1 == 1
});

until(condition, function() {
    // Check every second if 1 == 1 and do something.
}, '1 second');

until(condition, function() {
    // Check every second if 1 == 1 and do something.
}, 150, 'coolId');

clear

Syntactic sugar for clearInterval and clearTimeout

The clear() method can be used in 3 ways:

// Will clear all intervals and timeouts that where created with an id
clear();

// Will clear a timeout or interval given an id.
clear(id);

// The id can be two things.
var timeout = wait(100, callback);
clear(timeout);

wait(100, callback, 'awesome-id');
clear('awesome-id');

// Will clear all timeouts and intervals in an array.
clear([timeout, 'awesome-id']);

time

Time can be specified in various formats:

If time is a number, it will be interpreted as milliseconds.

100, 1 second, 3 minutes, 1 hour, 3 secs, 1 min, 2 hrs, 1s, 3m, 2h

Installation

npm install waitjs

Usage

// nodejs
require('waitjs');

<!-- browser -->
<script src="wait.js"></script>

Tests

npm test

Bitdeli Badge

wait's People

Contributors

bitdeli-chef avatar elving avatar iamyellow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.