From 838f371486ab3a083cee2471d8ee7f1f33acd595 Mon Sep 17 00:00:00 2001 From: Dmytro Maluka Date: Mon, 25 Mar 2024 17:11:12 +0100 Subject: [PATCH] Revert "Don't expose Go timers directly to lua" (#3211) * Revert "Don't expose Go timers directly to lua" This reverts commit 4ffc2206eeea4a7d58bdf283e35cdf28b29b0b42. Reason for revert: some plugins happen to use raw Go timers via time.AfterFunc(), in an unsafe way (without synchronizing their async code with micro). Let them keep doing that for now, in an unsafe way but at least without immediate crashes. Fixes #3209 * Add TODO about Go timers deprecation --- internal/lua/lua.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/lua/lua.go b/internal/lua/lua.go index e17f2a66..190dd95a 100644 --- a/internal/lua/lua.go +++ b/internal/lua/lua.go @@ -538,6 +538,15 @@ func importTime() *lua.LTable { L.SetField(pkg, "Minute", luar.New(L, time.Minute)) L.SetField(pkg, "Hour", luar.New(L, time.Hour)) + // TODO: these raw Go timer APIs don't provide any synchronization + // with micro. Stop exposing them to lua once plugins switch to using + // the safer micro.After() interface instead. See issue #3209 + L.SetField(pkg, "After", luar.New(L, time.After)) + L.SetField(pkg, "AfterFunc", luar.New(L, time.AfterFunc)) + L.SetField(pkg, "NewTicker", luar.New(L, time.NewTicker)) + L.SetField(pkg, "NewTimer", luar.New(L, time.NewTimer)) + L.SetField(pkg, "Tick", luar.New(L, time.Tick)) + return pkg }