Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

make interval optional to resolve #5 #6

Merged
merged 2 commits into from

2 participants

Fabien Veselin Todorov
Fabien

closes #5

Veselin Todorov vesln merged commit 760a3d7 into from
Veselin Todorov
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 8, 2014
  1. Fabien

    make interval optional

    fsbdev authored
  2. Fabien

    update readme

    fsbdev authored
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 3 deletions.
  1. +15 −0 Readme.md
  2. +6 −3 lib/ping.js
15 Readme.md
View
@@ -55,6 +55,21 @@ pin('http://google.com/')
})
```
+Run a one-off ping:
+
+```js
+var pin = require('pin');
+
+pin('http://google.com')
+ .up(function(response) {
+ console.log(response);
+ })
+ .down(function(error, response) {
+ console.log(error, response);
+ })
+ .check();
+```
+
Register custom validator:
```js
9 lib/ping.js
View
@@ -136,7 +136,7 @@ Ping.prototype.maxDuration = function(maxDuration) {
Ping.prototype.up = function(fn) {
this.on('up', fn);
- this.monitor();
+ if (this._interval) this.monitor();
return this;
};
@@ -150,7 +150,7 @@ Ping.prototype.up = function(fn) {
Ping.prototype.down = function(fn) {
this.on('down', fn);
- this.monitor();
+ if (this._interval) this.monitor();
return this;
};
@@ -161,6 +161,9 @@ Ping.prototype.down = function(fn) {
*/
Ping.prototype.monitor = function() {
+ if (!this._interval) {
+ throw new Error('An interval must be set in order to monitor.')
+ }
if (this.started) return;
var self = this;
@@ -174,7 +177,7 @@ Ping.prototype.monitor = function() {
/**
* Check if site is up or down.
*
- * @api private
+ * @api public
*/
Ping.prototype.check = function() {
Something went wrong with that request. Please try again.