coroutine

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่


ข้อมูลสรุป

ฟังก์ชัน
close(co: coroutine):boolean,Variant<string, ()>
finally(co: coroutine,callback: Variant)
resume(co: coroutine,...: Variant):boolean,Variant<Tuple, string>
yield(...: Tuple):Tuple<Variant>

เอกสารอ้างอิงเกี่ยวกับ API
ฟังก์ชัน
close
coroutine.close(co:coroutine):boolean,Variant<string, ()>
พารามิเตอร์
ส่งค่ากลับ
boolean, Variant<string, ()>
ตัวอย่างโค้ด
ปิด Coroutine

create
coroutine.create(f:function):coroutine
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
การสร้าง Coroutine

finally
coroutine.finally(
co:coroutine, callback:Variant)
พารามิเตอร์
callback:Variant
ตัวอย่างโค้ด
Coroutine Finally
local function observe(co, label)
coroutine.finally(co, function(status, ...)
print(label, status, ...)
end)
end
local finishing = coroutine.create(function()
return "ผลลัพธ์"
end)
observe(finishing, "finishing") --> finishing finished result
coroutine.resume(finishing)
local failing = coroutine.create(function()
error("ระเบิด", 0)
end)
observe(failing, "failing") --> failing error boom
coroutine.resume(failing)
local cancelled = coroutine.create(function()
coroutine.yield()
end)
coroutine.resume(cancelled)
observe(cancelled, "cancelled") --> cancelled cancelled
coroutine.close(cancelled)

isyieldable
coroutine.isyieldable():boolean
ส่งค่ากลับ
ตัวอย่างโค้ด
Coroutine สามารถหยุดได้

resume
coroutine.resume(
co:coroutine, ...:Variant
):boolean,Variant<Tuple, string>
พารามิเตอร์
...:Variant
ส่งค่ากลับ
boolean, Variant<Tuple, string>
ตัวอย่างโค้ด
การดำเนินการ Coroutine

running
coroutine.running():coroutine
ส่งค่ากลับ
ตัวอย่างโค้ด
การทำงานของ Coroutine

status
coroutine.status(co:coroutine):string
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
สถานะ Coroutine

wrap
coroutine.wrap(f:function):function
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
การห่อโครูทีน

yield
coroutine.yield(...:Tuple):Tuple<Variant>
พารามิเตอร์
...:Tuple
ส่งค่ากลับ
Tuple<Variant>
ตัวอย่างโค้ด
การหยุด Coroutine

©2026 Roblox Corporation. Roblox, โลโก้ Roblox และ Powering Imagination เป็นส่วนหนึ่งของเครื่องหมายการค้าที่จดทะเบียน และไม่ได้จดทะเบียนของเราในสหรัฐฯ และประเทศอื่นๆ