Skip to content

Commit

Permalink
fix(ui): task logs queue not flushed if not enough logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Jun 14, 2018
1 parent 4144efc commit 8753971
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions packages/@vue/cli-ui/src/graphql-api/connectors/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,26 +429,38 @@ function open (id, context) {
}

function logPipe (action) {
const maxTime = 100

let queue = ''
let size = 0
let time = Date.now()
let timeout

return {
add: (string) => {
queue += string
size++

if (size === 20 || Date.now() > time + 100) {
action(queue)
queue = ''
size = 0
time = Date.now()
}
},
flush: () => {
if (size) action(queue)
const add = (string) => {
queue += string
size++

if (size === 20 || Date.now() > time + maxTime) {
flush()
} else {
clearTimeout(timeout)
setTimeout(flush, maxTime)
}
}

const flush = () => {
clearTimeout(timeout)
if (!size) return
action(queue)
queue = ''
size = 0
time = Date.now()
}

return {
add,
flush
}
}

module.exports = {
Expand Down

0 comments on commit 8753971

Please sign in to comment.