◆コルーチンによるタイマスレッドみたいなの
を作ってみました。で、こんなの使うのだろうか。。。よくわかりませんw
isTimeout = false
--タイムアウトハンドラ
function timeOutHandler(_limit)
isTimeout = true
end
--タイマコルーチン用関数
function timer(_limit, callBack)
local limit = _limit --リミット
local startTime = os.time() --開始時間
local latest = os.time() --前回の時間
local countDown = _limit --カウントダウン用
print(countDown)
while true do
local time = os.time()
if startTime + limit <= os.time() then
break
elseif latest < time then
print(coroutine.status(co))
latest = time
countDown = countDown - 1
print(countDown)
end
coroutine.yield() --コルーチンを中断して処理をもどす
end
callBack(limit) --コールバック関数を呼ぶ
end
co = coroutine.create(timer) --コルーチンの生成
print(coroutine.status(co)) --ステータスの表示
--メインループ
repeat
coroutine.resume(co, 10, timeOutHandler) --コルーチンの開始と再開
until isTimeout
print(coroutine.status(co))
print("time out")
0 件のコメント:
コメントを投稿