# Installation

Use npm command in order to install bh-smart-cron:

```bash
npm install [--save] bh-smart-cron
```

# bh-smart-cron

The bh-smart-cron module allows to manage planned tasks inside NodeJS program.

When I should use bh-smart-cron ?

  - When I want to repeat a task every x seconds
  - When I want to plan a task for a specific moment of a day

# Usage example:

## Planify a "hello world" task every 10 seconds and start immediatly

```js
const BHSmartCron = require('bh-smart-cron');
const Q = require('q');

var cron = new BHSmartCron(0, 10, () => {
  console.log('hello world');

  return Q.resolve();
});

cron.start(true);
```

Note: passing true to start signify "start immediatly".

## Planify 3 "hello world" tasks and wait the end of the process

```js
const BHSmartCron = require('bh-smart-cron');
const Q = require('q');

var counter = 0;
var cron = new BHSmartCron(0, 10, () => {
  console.log('hello world');

  ++counter:

  if (counter === 3) {
    return Q.reject();
  }

  return Q.resolve();
});

cron
  .start(true)
  .then(() => {
    console.log('end');
  })
;
```

## Planify a "hellow world" task at 1:00 am every day:

```js
const BHSmartCron = require('bh-smart-cron');
const Q = require('q');

var cron = new BHSmartCron(3600, 86400, () => {
  console.log('hello world');

  return Q.resolve();
});

cron.start();
```
