app.wait

1.0.1 • Public • Published

Что это?

App.wait — это npm-пакет с помощью которого вы можете создавать искусственные задержки через await.

Установка

$ npm i app.wait

Пример

const wait = require('app.wait');

(async () => {
    let t = new Date().getTime();
    
    await wait(1000);
    console.log(new Date().getTime() - t);
    
    await wait(1000);
    console.log(new Date().getTime() - t);
    
    await wait(1000);
    console.log(new Date().getTime() - t);
    
    await wait(1000);
    console.log(new Date().getTime() - t);
    
    //=> 1004
    //=> 2012
    //=> 3014
    //=> 4015
})();

Исходный код

module.exports = (ms) => {
    return new Promise((resolve) => {
        setTimeout(resolve, ms);
    });
};

Как мы видим это просто promise обернутый в setTimeout.

Package Sidebar

Install

npm i app.wait

Weekly Downloads

0

Version

1.0.1

License

none

Unpacked Size

4.14 kB

Total Files

6

Last publish

Collaborators

  • classtype