Skip to content

Commit

Permalink
feat: track if a goroutine has made progress
Browse files Browse the repository at this point in the history
This is done by keeping track of what is the last instruction that is
executed by the goroutine. `progress = prev_instruction !==
curr_instruction`
  • Loading branch information
shenyih0ng committed Apr 7, 2024
1 parent 8fd8dd9 commit c840623
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/go-slang/goroutine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ export class GoRoutine {
private context: Context
private scheduler: Scheduler

// used to determine if the goroutine made progress in the last tick
public progress: boolean = false
private prevInst: Instruction | null = null

public state: GoRoutineState
public isMain: boolean

Expand All @@ -114,6 +118,9 @@ export class GoRoutine {
Result.ok(C.isEmpty() ? GoRoutineState.Exited : GoRoutineState.Running)

this.state = nextState.isSuccess ? nextState.unwrap() : GoRoutineState.Exited
this.progress = this.prevInst !== inst
this.prevInst = inst

return nextState
}
}
Expand Down

0 comments on commit c840623

Please sign in to comment.