From bbff7098c20d7ee764f7680f92790cf1cfcdea21 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Sat, 21 May 2022 11:53:44 -0400 Subject: [PATCH] feat: add jobs.last function to get last job --- job.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/job.go b/job.go index f16bacf..b0863b6 100644 --- a/job.go +++ b/job.go @@ -215,6 +215,7 @@ func (j *jobHandler) stopAll() { func (j *jobHandler) loader(rtm *rt.Runtime) *rt.Table { jobFuncs := map[string]util.LuaExport{ "all": {j.luaAllJobs, 0, false}, + "last": {j.luaLastJob, 0, false}, "get": {j.luaGetJob, 1, false}, "add": {j.luaAddJob, 2, false}, "disown": {j.luaDisownJob, 1, false}, @@ -299,3 +300,16 @@ func (j *jobHandler) luaDisownJob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { return c.Next(), nil } + +func (j *jobHandler) luaLastJob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { + j.mu.RLock() + defer j.mu.RUnlock() + + job := j.jobs[j.latestID] + if job == nil { // incase we dont have any jobs yet + return c.Next(), nil + } + + return c.PushingNext1(t.Runtime, job.lua()), nil +} +