下面我有两个功能,我需要按顺序执行它们,只有当第一个完成的下次运行。但是,这不仅仅是输出第二个功能。运行功能
在原料Lua中,我们可以使用CALLBACK_MANAGER:FireCallbacks
和CALLBACK_MANAGER:RegisterCallback
处理这个问题。我怎么能继续esp8266?
-- test.lua
function increase()
a = 0
tmr.alarm(1,1000,1,function()
if (a == 10) then
tmr.stop(1)
else
a = a + 1
end
print(a)
end)
end
function decrease()
a = 10
tmr.alarm(1,1000,1,function()
if (a == 0) then
tmr.stop(1)
else
a = a - 1
end
print(a)
end)
end
function start()
increase()
decrease()
end
start()
输出
➜ test git:(master) ✗ nu exec test.lua
➜ test git:(master) ✗ nu terminal
-- output
--- Miniterm on /dev/cu.wchusbserial1410 115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
10
9
8
7
6
5
4
3
2
1
任何想法?提前致谢!
当所有增加的作业完成时,您应该从'increase()'内部调用'decrease()'。 –
这是一个好方法吗?如果有一段时间我只需要执行'increase()'会怎么样? – hugalves