Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteb16da2

Browse files
committed
setup basic throttle debounce for tests
1 parentd302814 commiteb16da2

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

‎src/services/testRunner/index.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
importnodefrom'../../services/node'
22
import{getOutputChannel}from'../../editor/outputChannel'
33
importparserfrom'./parser'
4-
//import {setLatestProcess, isLatestProcess } from './throttle'
4+
import{throttle,debounce}from'./throttle'
55

66
exportinterfacePayload{
77
stepId:string
@@ -22,6 +22,11 @@ const createTestRunner = (config: TestRunnerConfig, callbacks: Callbacks) => {
2222
constoutputChannelName='TEST_OUTPUT'
2323

2424
returnasync(payload:Payload,onSuccess?:()=>void):Promise<void>=>{
25+
conststartTime=throttle()
26+
// throttle time early
27+
if(!startTime){
28+
return
29+
}
2530
console.log('------------------- RUN TEST -------------------')
2631

2732
// flag as running
@@ -33,6 +38,14 @@ const createTestRunner = (config: TestRunnerConfig, callbacks: Callbacks) => {
3338
}catch(err){
3439
result={stdout:err.stdout,stderr:err.stack}
3540
}
41+
42+
// ignore output if not latest process
43+
// this is a crappy version of debounce
44+
if(!debounce(startTime)){
45+
return
46+
}
47+
console.log('----------------- PROCESS TEST -----------------')
48+
3649
const{ stdout, stderr}=result
3750

3851
consttap=parser(stdout||'')

‎src/services/testRunner/throttle.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
// ensure only latest run_test action is taken
2-
letcurrentId=0
2+
letlastRun=newDate()
33

4-
exportconstsetLatestProcess=()=>currentId++
4+
constTHROTTLE_OFFSET=300// ms
5+
6+
exportconstthrottle=():Date|null=>{
7+
constnow=newDate()
8+
if(now.getTime()>lastRun.getTime()+THROTTLE_OFFSET){
9+
lastRun=now
10+
returnlastRun
11+
}
12+
returnnull
13+
}
514

615
// quick solution to prevent processing multiple results
7-
// NOTE: may be possible to kill child process early
8-
exportconstisLatestProcess=(processId:number):boolean=>currentId===processId
16+
// NOTE: may be possible to kill child process early if we migrate to tasks
17+
exportconstdebounce=(startTime:Date):boolean=>lastRun===startTime

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp