Skip to content

Commit

Permalink
asynchronous commands to run in a sub-shell
Browse files Browse the repository at this point in the history
  • Loading branch information
yassinebenaid committed Jan 25, 2025
1 parent 2088c33 commit e3208ac
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,17 @@ func (g *generator) handleParameterAssignment(buf *InstructionBuffer, p ast.Para
}

func (g *generator) handleBackgroundConstruction(buf *InstructionBuffer, b ast.BackgroundConstruction) {
buf.add(ir.Set{Name: "shell.ExitCode", Value: ir.Literal("0")})
buf.add(ir.Literal("shell.WaitGroup.Add(1)\n"))
var scope InstructionBuffer

scope.add(ir.Set{Name: "shell.ExitCode", Value: ir.Literal("0")})
scope.add(ir.Literal("shell.WaitGroup.Add(1)\n"))
scope.add(ir.Declare{Name: "done", Value: ir.Literal("shell.WaitGroup.Done")})
scope.add(ir.CloneShell{})

var body InstructionBuffer
body.add(ir.Literal("defer shell.WaitGroup.Done()\n"))
body.add(ir.Literal("defer done()\n"))
g.generate(&body, b.Statement, &context{})
buf.add(ir.Gorouting(body))
scope.add(ir.Gorouting(body))

buf.add(ir.Scope(scope))
}

0 comments on commit e3208ac

Please sign in to comment.