diff --git a/index.js b/index.js index 3e2d5805..ebd4afb9 100644 --- a/index.js +++ b/index.js @@ -55,16 +55,6 @@ var warning = 'Warning: connect.session() MemoryStore is not\n' + 'designed for a production environment, as it will leak\n' + 'memory, and will not scale past a single process.'; -/** - * Node.js 0.8+ async implementation. - * @private - */ - -/* istanbul ignore next */ -var defer = typeof setImmediate === 'function' - ? setImmediate - : function(fn){ process.nextTick(fn.bind.apply(fn, arguments)) } - /** * Setup session store with the given `options`. * @@ -246,7 +236,7 @@ function session(options) { try { setcookie(res, name, req.sessionID, secrets[0], req.session.cookie.data) } catch (err) { - defer(next, err) + setImmediate(next, err) } }); @@ -316,7 +306,7 @@ function session(options) { debug('destroying'); store.destroy(req.sessionID, function ondestroy(err) { if (err) { - defer(next, err); + setImmediate(next, err); } debug('destroyed'); @@ -341,7 +331,7 @@ function session(options) { if (shouldSave(req)) { req.session.save(function onsave(err) { if (err) { - defer(next, err); + setImmediate(next, err); } writeend(); @@ -353,7 +343,7 @@ function session(options) { debug('touching'); store.touch(req.sessionID, req.session, function ontouch(err) { if (err) { - defer(next, err); + setImmediate(next, err); } debug('touched'); diff --git a/session/memory.js b/session/memory.js index 11ed686c..2008939a 100644 --- a/session/memory.js +++ b/session/memory.js @@ -16,16 +16,6 @@ var Store = require('./store') var util = require('util') -/** - * Shim setImmediate for node.js < 0.10 - * @private - */ - -/* istanbul ignore next */ -var defer = typeof setImmediate === 'function' - ? setImmediate - : function(fn){ process.nextTick(fn.bind.apply(fn, arguments)) } - /** * Module exports. */ @@ -68,7 +58,7 @@ MemoryStore.prototype.all = function all(callback) { } } - callback && defer(callback, null, sessions) + callback && setImmediate(callback, null, sessions) } /** @@ -80,7 +70,7 @@ MemoryStore.prototype.all = function all(callback) { MemoryStore.prototype.clear = function clear(callback) { this.sessions = Object.create(null) - callback && defer(callback) + callback && setImmediate(callback) } /** @@ -92,7 +82,7 @@ MemoryStore.prototype.clear = function clear(callback) { MemoryStore.prototype.destroy = function destroy(sessionId, callback) { delete this.sessions[sessionId] - callback && defer(callback) + callback && setImmediate(callback) } /** @@ -104,7 +94,7 @@ MemoryStore.prototype.destroy = function destroy(sessionId, callback) { */ MemoryStore.prototype.get = function get(sessionId, callback) { - defer(callback, null, getSession.call(this, sessionId)) + setImmediate(callback, null, getSession.call(this, sessionId)) } /** @@ -118,7 +108,7 @@ MemoryStore.prototype.get = function get(sessionId, callback) { MemoryStore.prototype.set = function set(sessionId, session, callback) { this.sessions[sessionId] = JSON.stringify(session) - callback && defer(callback) + callback && setImmediate(callback) } /** @@ -153,7 +143,7 @@ MemoryStore.prototype.touch = function touch(sessionId, session, callback) { this.sessions[sessionId] = JSON.stringify(currentSession) } - callback && defer(callback) + callback && setImmediate(callback) } /** diff --git a/test/support/smart-store.js b/test/support/smart-store.js index 8b224fdd..5e1bfb2f 100644 --- a/test/support/smart-store.js +++ b/test/support/smart-store.js @@ -3,11 +3,6 @@ var session = require('../../') var util = require('util') -/* istanbul ignore next */ -var defer = typeof setImmediate === 'function' - ? setImmediate - : function(fn){ process.nextTick(fn.bind.apply(fn, arguments)) } - module.exports = SmartStore function SmartStore () { @@ -19,7 +14,7 @@ util.inherits(SmartStore, session.Store) SmartStore.prototype.destroy = function destroy (sid, callback) { delete this.sessions[sid] - defer(callback, null) + setImmediate(callback, null) } SmartStore.prototype.get = function get (sid, callback) { @@ -45,10 +40,10 @@ SmartStore.prototype.get = function get (sid, callback) { } } - defer(callback, null, sess) + setImmediate(callback, null, sess) } SmartStore.prototype.set = function set (sid, sess, callback) { this.sessions[sid] = JSON.stringify(sess) - defer(callback, null) + setImmediate(callback, null) }