Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

call close handler with correct parameters #56

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ jspm_packages

# vim swap files
*.swp

# vscode
*.code-workspace
.vscode
26 changes: 16 additions & 10 deletions boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function Boot (server, opts, done) {
this._server = server
this._current = []
this._error = null
this._isOnCloseHandlerKey = Symbol('isOnCloseHandler')

this.setMaxListeners(0)

Expand Down Expand Up @@ -210,6 +211,7 @@ Boot.prototype.after = function (func) {
}

Boot.prototype.onClose = function (func) {
func[this._isOnCloseHandlerKey] = true
this._closeQ.unshift(func, callback.bind(this))

function callback (err) {
Expand Down Expand Up @@ -305,21 +307,25 @@ function callWithCbOrNextTick (func, cb, context) {

function closeWithCbOrNextTick (func, cb, context) {
context = this._server
if (this._closeQ.length() === 0 && this._thereIsCloseCb) {
if (func.length === 0 || func.length === 1) {
var isOnCloseHandler = func[this._isOnCloseHandlerKey]
if (func.length === 0 || func.length === 1) {
if (isOnCloseHandler) {
func(context)
} else {
func(this._error)
process.nextTick(cb)
} else if (func.length === 2) {
func(this._error, cb)
}
process.nextTick(cb)
} else if (func.length === 2) {
if (isOnCloseHandler) {
func(context, cb)
} else {
func(this._error, context, cb)
func(this._error, cb)
}
} else {
if (func.length === 0 || func.length === 1) {
func(context)
process.nextTick(cb)
} else {
if (isOnCloseHandler) {
func(context, cb)
} else {
func(this._error, context, cb)
}
}
}
Expand Down