From eef9fba1611231d4b2604cb69595253fb0f1be90 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Fri, 11 Aug 2023 20:57:50 +0200 Subject: [PATCH] core.Delayed(): more generally usable version --- core/core.go | 19 ++++++++----------- tests/etc/etc.go | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/core/core.go b/core/core.go index 2e7dcd1..dd92cee 100644 --- a/core/core.go +++ b/core/core.go @@ -10,6 +10,14 @@ import ( "git.sr.ht/~cco/go-scopes/logging" ) +func Delayed(proc lib.Proc, delay time.Duration) lib.Proc { + return func(ctx lib.Context) { + logging.Debug(ctx).Int("delay", int(delay)).Msg("lib.Delayed") + time.Sleep(delay * time.Millisecond) + proc(ctx) + } +} + func None(_ lib.Context) {} func Start(ctx lib.Context) { @@ -17,17 +25,6 @@ func Start(ctx lib.Context) { lib.RunCtx(ctx, Listen) } -func DelayedStart(starter lib.StartProc, delay time.Duration) lib.StartProc { - if starter == nil { - starter = Start - } - return func(ctx lib.Context) { - logging.Debug(ctx).Int("delay", int(delay)).Msg("core.DelayedStart") - time.Sleep(delay * time.Millisecond) - starter(ctx) - } -} - func Listen(ctx lib.Context) { step := ctx.Config().Step() for step(ctx) { diff --git a/tests/etc/etc.go b/tests/etc/etc.go index f48d02d..e1a3841 100644 --- a/tests/etc/etc.go +++ b/tests/etc/etc.go @@ -35,7 +35,7 @@ func Config() lib.Config { server_c.AddRoute("/api", server.MsgHandler("demo", nil, "test-receiver")) test_client := &client.Cfg{ - BaseCfg: b("test-client", core.DelayedStart(core.Start, 50)), + BaseCfg: b("test-client", core.Delayed(core.Start, 50)), Url: ovr("http://localhost:8123/api", SERVER_URL), } test_client.AddAction("demo", action.Base(client.Send))