Skip to content

Commit 8753971

Browse files
author
Guillaume Chau
committed
fix(ui): task logs queue not flushed if not enough logs
1 parent 4144efc commit 8753971

File tree

1 file changed

+26
-14
lines changed
  • packages/@vue/cli-ui/src/graphql-api/connectors

1 file changed

+26
-14
lines changed

packages/@vue/cli-ui/src/graphql-api/connectors/tasks.js

+26-14
Original file line numberDiff line numberDiff line change
@@ -429,26 +429,38 @@ function open (id, context) {
429429
}
430430

431431
function logPipe (action) {
432+
const maxTime = 100
433+
432434
let queue = ''
433435
let size = 0
434436
let time = Date.now()
437+
let timeout
435438

436-
return {
437-
add: (string) => {
438-
queue += string
439-
size++
440-
441-
if (size === 20 || Date.now() > time + 100) {
442-
action(queue)
443-
queue = ''
444-
size = 0
445-
time = Date.now()
446-
}
447-
},
448-
flush: () => {
449-
if (size) action(queue)
439+
const add = (string) => {
440+
queue += string
441+
size++
442+
443+
if (size === 20 || Date.now() > time + maxTime) {
444+
flush()
445+
} else {
446+
clearTimeout(timeout)
447+
setTimeout(flush, maxTime)
450448
}
451449
}
450+
451+
const flush = () => {
452+
clearTimeout(timeout)
453+
if (!size) return
454+
action(queue)
455+
queue = ''
456+
size = 0
457+
time = Date.now()
458+
}
459+
460+
return {
461+
add,
462+
flush
463+
}
452464
}
453465

454466
module.exports = {

0 commit comments

Comments
 (0)