Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

bind vip.status to vip & use async close

  • Loading branch information...
commit 67873802cd50cbce5f2bd1f4ce53e5a4a8943397 1 parent cba7249
@q3boy authored
View
14 lib/vip-resp.coffee
@@ -13,7 +13,7 @@ class VipStatus
success_body : 'success'
timeout : 2000
, options
- @status.bind @
+ @status = @status.bind @
@force = 'auto'
@net = null
@listen()
@@ -26,10 +26,14 @@ class VipStatus
@force = 'auto' if @force isnt 'on' and @force isnt 'off'
.listen @options.sock_path
- close : ->
- return if not @net
- @net.close()
- try fs.unlink @options.sock_path
+ close : (cb)->
+ return cb null if not @net
+ @net.close =>
+ if fs.existsSync @options.sock_path
+ fs.unlink @options.sock_path, cb
+ else
+ cb null
+ # try fs.unlinkSync @options.sock_path
response = (resp, code, phrase) ->
resp.setHeader 'Content-Type', 'text/plain'
View
18 out/release/lib/vip-resp.js
@@ -27,7 +27,7 @@ VipStatus = (function() {
success_body: 'success',
timeout: 2000
}, options);
- this.status.bind(this);
+ this.status = this.status.bind(this);
this.force = 'auto';
this.net = null;
this.listen();
@@ -48,14 +48,18 @@ VipStatus = (function() {
}).listen(this.options.sock_path);
};
- VipStatus.prototype.close = function() {
+ VipStatus.prototype.close = function(cb) {
+ var _this = this;
if (!this.net) {
- return;
+ return cb(null);
}
- this.net.close();
- try {
- return fs.unlink(this.options.sock_path);
- } catch (_error) {}
+ return this.net.close(function() {
+ if (fs.existsSync(_this.options.sock_path)) {
+ return fs.unlink(_this.options.sock_path, cb);
+ } else {
+ return cb(null);
+ }
+ });
};
response = function(resp, code, phrase) {
View
2  package.json
@@ -1,7 +1,7 @@
{
"name": "vip-resp",
"main": "out/release/lib/nvsr.js",
- "version": "0.0.1",
+ "version": "0.0.2",
"description": "vip status check responser",
"author": {
"name": "q3boy",
View
2  package.yaml
@@ -1,6 +1,6 @@
name: vip-resp
main: out/release/lib/nvsr.js
-version: 0.0.1
+version: 0.0.2
description: vip status check responser
author:
name: q3boy
View
4 tests/test-vip-resp.coffee
@@ -30,8 +30,8 @@ describe 'Node Vip StatusCode Responser', ->
s = null
flag = 0
mock.clean()
- afterEach ->
- s.close() if s
+ afterEach (done)->
+ s.close(done) if s and s.close
sock = __dirname + "/test-vr.sock"
options =
check_health: (cb)->
Please sign in to comment.
Something went wrong with that request. Please try again.