Introduction
This tool is intended to be used either in bash or a node.js project. It waits for a resource (such as a database) to become available, then it starts another process. It just chills until the timeout expires or the wait condition is satisfied.
Let's illustrate with an example. Say you have a Docker Compose environment that starts containers S and D (for database). S depends on D, but D can be slow to start up. S can use chillin in either of two ways.
- The NodeJS startup script can be modified to use the chillin NPM package.
- A startup bash script can utilize the chillin CLI.
Please Note Chillin uses EcmaScript 6. It will not run on older versions of NodeJS!
NodeJS Example
const chillin = promise = chillin start promise
To Run Chillin Inside Your Project
> npm install chillin --save-dev
> export PATH=$PATH:$(npm bin)
> chillin port www.google.com 80
BASH Example
Please reference the example above if you are installing Chillin in your project rather than as a global package. The line that changes the PATH variable can be added to the example below to make it run with a locally installed package.
#!/usr/bin/env bash #If you want to suppress error output on failure, you can redirect #stderr to null on the next line. chillin port $1 5432#Get the exit code RESULT=$?
Types of Waits
There are three built-in waiter modules: port, exec, and mock. The port waiter is shown in the examples. The exec module waits for a process to start and complete or time out. The mock module is for testing purposes. Other modules may be loaded using a path consistent with require() in NodeJS.
The port Waiter
chillin www.github.com 80 --timeout 2000
The positional arguments are ADDRESS PORT
The exec Waiter
chillin --timeout 2000 echo "Hello"
The positional arguments correspond to COMMAND arg1 arg2 ... argN