Skip to content

Commit

Permalink
Merge 254ea5d into f1e85dc
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 authored Jul 23, 2020
2 parents f1e85dc + 254ea5d commit a328c65
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 16 deletions.
8 changes: 4 additions & 4 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

tmp
test
tasks
#tasks
/tools/
docs
client
#client
logo
integration-tests

Expand All @@ -16,8 +16,8 @@ Gruntfile.coffee
credentials
Karma.sublime-*

static/karma.src.js
static/karma.wrapper
#static/karma.src.js
#static/karma.wrapper
test-results.xml
thesis.pdf
mocha-watch.sh
Expand Down
51 changes: 39 additions & 12 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,32 @@ class Server extends KarmaEventEmitter {
return this._fileList ? this._fileList.changeFile(path) : Promise.resolve()
}

emitExitAsync (code) {
const name = 'exit'
let pending = this.listeners(name).length
const deferred = helper.defer()

function resolve () {
deferred.resolve(code)
}

this.emit(name, (newCode) => {
if (newCode && typeof newCode === 'number') {
// Only update code if it is given and not zero
code = newCode
}
if (!--pending) {
resolve()
}
})

if (!pending) {
resolve()
}

return deferred.promise
}

async _start (config, launcher, preprocess, fileList, capturedBrowsers, executor, done) {
if (config.detached) {
this._detach(config, done)
Expand Down Expand Up @@ -356,21 +382,22 @@ class Server extends KarmaEventEmitter {
}
})

let removeAllListenersDone = false
const removeAllListeners = () => {
if (removeAllListenersDone) {
return
}
removeAllListenersDone = true
webServer.removeAllListeners()
processWrapper.removeAllListeners()
done(code || 0)
}

return this.emitAsync('exit').then(() => {
return this.emitExitAsync(code).then((code) => {
return new Promise((resolve, reject) => {
socketServer.sockets.removeAllListeners()
socketServer.close()

let removeAllListenersDone = false
const removeAllListeners = () => {
if (removeAllListenersDone) {
return
}
removeAllListenersDone = true
webServer.removeAllListeners()
processWrapper.removeAllListeners()
done(code || 0)
}

const closeTimeout = setTimeout(removeAllListeners, webServerCloseTimeout)

webServer.close(() => {
Expand Down

0 comments on commit a328c65

Please sign in to comment.