@@ -54,20 +54,18 @@ export function createCustomConsole(defaultState?: WorkerGlobalState) {
54
54
} )
55
55
}
56
56
function sendStdout ( taskId : string ) {
57
- const buffer = stdoutBuffer . get ( taskId )
58
- if ( ! buffer )
59
- return
60
- sendBuffer ( buffer , taskId , 'stdout' )
57
+ sendBuffer ( 'stdout' , taskId )
61
58
}
62
59
63
60
function sendStderr ( taskId : string ) {
64
- const buffer = stderrBuffer . get ( taskId )
65
- if ( ! buffer )
66
- return
67
- sendBuffer ( buffer , taskId , 'stderr' )
61
+ sendBuffer ( 'stderr' , taskId )
68
62
}
69
63
70
- function sendBuffer ( buffer : any [ ] , taskId : string , type : 'stdout' | 'stderr' ) {
64
+ function sendBuffer ( type : 'stdout' | 'stderr' , taskId : string ) {
65
+ const buffers = type === 'stdout' ? stdoutBuffer : stderrBuffer
66
+ const buffer = buffers . get ( taskId )
67
+ if ( ! buffer )
68
+ return
71
69
if ( state ( ) . config . printConsoleTrace ) {
72
70
buffer . forEach ( ( [ buffer , origin ] ) => {
73
71
sendLog ( type , taskId , String ( buffer ) , buffer . length , origin )
@@ -78,7 +76,7 @@ export function createCustomConsole(defaultState?: WorkerGlobalState) {
78
76
sendLog ( type , taskId , content , buffer . length )
79
77
}
80
78
const timer = timers . get ( taskId ) !
81
- stderrBuffer . set ( taskId , [ ] )
79
+ buffers . set ( taskId , [ ] )
82
80
if ( type === 'stderr' )
83
81
timer . stderrTime = 0
84
82
else
@@ -93,11 +91,12 @@ export function createCustomConsole(defaultState?: WorkerGlobalState) {
93
91
origin ?: string ,
94
92
) {
95
93
const timer = timers . get ( taskId ) !
94
+ const time = type === 'stderr' ? timer . stderrTime : timer . stdoutTime
96
95
state ( ) . rpc . onUserConsoleLog ( {
97
96
type,
98
97
content : content || '<empty line>' ,
99
98
taskId,
100
- time : timer . stderrTime || RealDate . now ( ) ,
99
+ time : time || RealDate . now ( ) ,
101
100
size,
102
101
origin,
103
102
} )
0 commit comments