Skip to content

Commit

Permalink
Rename item to job, add functionality comments
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Sep 30, 2018
1 parent cdf42fc commit 1e13588
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions index.js
Expand Up @@ -124,12 +124,15 @@ function onchange (match, command, rawargs, opts = {}) {
// Too many jobs running already.
if (running.size >= jobs) return

const item = queue.popLeft()
running.add(item)
// Remove first job from queue (FIFO).
const job = queue.popLeft()

// Add job to running set.
running.add(job)

// Start the process and remove when finished.
item.start(cwd, log, stdout, stderr, () => {
running.delete(item)
job.start(cwd, log, stdout, stderr, () => {
running.delete(job)
if (delay > 0) return setTimeout(dequeue, delay)
return dequeue()
})
Expand Down Expand Up @@ -168,7 +171,7 @@ function onchange (match, command, rawargs, opts = {}) {
return enqueue(event, changed)
})

// Notify external listener for "ready".
// Notify external listener of "ready" event.
ready()
})

Expand Down Expand Up @@ -197,5 +200,5 @@ function outpipetmpl (str) {

// Simple exit message generator.
function exitmsg (code, signal) {
return code == null ? `exited with ${signal}` : `completed with code ${code}`
return code == null ? `exited with ${signal}` : `completed with ${code}`
}

0 comments on commit 1e13588

Please sign in to comment.