From 7b7e0ebccc100ffa931c182e472dd3c6e1f820d7 Mon Sep 17 00:00:00 2001 From: HAYAMA_Kaoru Date: Thu, 5 Dec 2024 11:17:50 +0900 Subject: [PATCH] Implement `(wait PID)` --- global.go | 15 +++++++++++++++ main.go | 1 + 2 files changed, 16 insertions(+) diff --git a/global.go b/global.go index 26f50a0..a345960 100644 --- a/global.go +++ b/global.go @@ -214,3 +214,18 @@ func (g *Global) setenv(ctx context.Context, w *gmnlisp.World, __key, __val gmnl return gmnlisp.Null, os.Setenv(key, val) } + +func (g *Global) wait(ctx context.Context, w *gmnlisp.World, pidNode gmnlisp.Node) (gmnlisp.Node, error) { + pidInteger, err := gmnlisp.ExpectClass[gmnlisp.Integer](ctx, w, pidNode) + if err != nil { + return nil, err + } + pid := int(pidInteger) + + process, err := os.FindProcess(pid) + if err != nil { + return gmnlisp.Null, nil + } + _, err = process.Wait() + return gmnlisp.Null, err +} diff --git a/main.go b/main.go index 7254ffa..72cd26e 100644 --- a/main.go +++ b/main.go @@ -39,6 +39,7 @@ func mains(args []string) error { gmnlisp.NewSymbol("expect"): gmnlisp.SpecialF(g.expect), gmnlisp.NewSymbol("getenv"): gmnlisp.Function1(g.getenv), gmnlisp.NewSymbol("setenv"): gmnlisp.Function2(g.setenv), + gmnlisp.NewSymbol("wait"): gmnlisp.Function1(g.wait), }) if len(args) <= 0 {