@meteorjs/ddp-graceful-shutdown
Advanced tools
Comparing version 1.0.0-beta.4 to 1.0.0-beta.5
@@ -7,2 +7,4 @@ 'use strict'; | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -74,27 +76,46 @@ | ||
key: 'closeOneConnectionAndScheduleNext', | ||
value: function closeOneConnectionAndScheduleNext(delay) { | ||
var _this2 = this; | ||
value: function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(delay) { | ||
var _this2 = this; | ||
Promise.resolve().then(function () { | ||
var _connections$entries$ = _this2.connections.entries().next(), | ||
done = _connections$entries$.done, | ||
value = _connections$entries$.value; | ||
var _connections$entries$, done, value, _value, id, conn; | ||
if (done) { | ||
return; | ||
} | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_connections$entries$ = this.connections.entries().next(), done = _connections$entries$.done, value = _connections$entries$.value; | ||
var _value = _slicedToArray(value, 2), | ||
id = _value[0], | ||
conn = _value[1]; | ||
if (!done) { | ||
_context.next = 3; | ||
break; | ||
} | ||
_this2.connections.delete(id); | ||
conn.close(); | ||
if (_this2.connections.size > 0) { | ||
setTimeout(function () { | ||
return _this2.closeOneConnectionAndScheduleNext(delay); | ||
}, delay); | ||
} | ||
}); | ||
} | ||
return _context.abrupt('return'); | ||
case 3: | ||
_value = _slicedToArray(value, 2), id = _value[0], conn = _value[1]; | ||
this.connections.delete(id); | ||
conn.close(); | ||
if (this.connections.size > 0) { | ||
setTimeout(function () { | ||
return _this2.closeOneConnectionAndScheduleNext(delay); | ||
}, delay); | ||
} | ||
case 7: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
function closeOneConnectionAndScheduleNext(_x2) { | ||
return _ref3.apply(this, arguments); | ||
} | ||
return closeOneConnectionAndScheduleNext; | ||
}() | ||
}]); | ||
@@ -101,0 +122,0 @@ |
{ | ||
"name": "@meteorjs/ddp-graceful-shutdown", | ||
"version": "1.0.0-beta.4", | ||
"version": "1.0.0-beta.5", | ||
"description": "Close DDP connections gradually on server shutdown", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -46,15 +46,13 @@ // DDPGracefulShutdown is a class which tracks open connections in a DDP server | ||
// the code in a Fiber by calling it from meteor-promise's queue. | ||
closeOneConnectionAndScheduleNext(delay) { | ||
Promise.resolve().then(() => { | ||
const {done, value} = this.connections.entries().next(); | ||
if (done) { | ||
return; | ||
} | ||
const [id, conn] = value; | ||
this.connections.delete(id); | ||
conn.close(); | ||
if (this.connections.size > 0) { | ||
setTimeout(() => this.closeOneConnectionAndScheduleNext(delay), delay); | ||
} | ||
}); | ||
async closeOneConnectionAndScheduleNext(delay) { | ||
const {done, value} = this.connections.entries().next(); | ||
if (done) { | ||
return; | ||
} | ||
const [id, conn] = value; | ||
this.connections.delete(id); | ||
conn.close(); | ||
if (this.connections.size > 0) { | ||
setTimeout(() => this.closeOneConnectionAndScheduleNext(delay), delay); | ||
} | ||
} | ||
@@ -61,0 +59,0 @@ } |
10918
161