Socket
Socket
Sign inDemoInstall

rewait

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    rewait

Wait for external resources to become available -- http, https, tcp, sockets, files, and custom functions.


Version published
Weekly downloads
43
decreased by-41.89%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Rewait

Version 2.0.0 License MIT Test Coverage 100%

A NodeJS library to wait for external resources to become available:

  • files
  • sockets
  • http/https
  • custom functions

For example, you may wish to wait for a database or message queue to become available before starting your HTTP server. Rewait does that.

Install

Easily install with the following NPM command, or download a release.

npm i rewait

Why use rewait?

  • No dependencies
  • Tiny (~400 logical lines of code)
  • 100% test coverage
  • Permissive FOSS license
  • Written in TypeScript
  • Used in major production evironments
  • Extensible

Usage

For detailed usage info, see the API documentation here.

Example

See more examples here.

const { retry, http, socket } = require('rewait')

retry(
  [
    http('http://localhost:3000'),
    http('https://localhost:3001/path/to/thing.txt'),
    socket('/var/run/app.sock'),
  ],
  {
    interval: 250, // check (at most) every 1/4 second
    timeout: 60000, // timeout after 60 seconds (on the dot)
  }
).then(() => {
  console.log('Ready!')
})

Custom checks

If you need custom functionality, you can easily write your own custom checks.

Simply throw an Error when "not ready".

Example:

function customCheck(options = {}) {
  return new Promise(function() {
    if (options.neverReady) {
      throw new Error('Never ready!')
    }
    if (options.waitUntil) {
      if (+new Date() < options.waitUntil) {
        throw new Error('Not ready!')
      }
    }
    // Ready, simply by not throwing
  })
}

Keywords

FAQs

Last updated on 23 Feb 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc