MightyPirates / OpenComputers

Home of the OpenComputers mod for Minecraft.
https://oc.cil.li
Other
1.59k stars 431 forks source link

Why Not Yield In Debug Hook? #94

Closed ghost closed 10 years ago

ghost commented 10 years ago

Currently Execute time are limited. (1 second default, while 10 second are provided by ComputerCraft) But i want OpenComputer are support long execute time. (And If you can OpenPeripheral also.)

CODE

co = coroutine.create((function() for i = 1, 15 do print(i) end end))
debug.sethook(co, function () print("?", 1, coroutine.yield("A")) end, "", 25);

status = true
while status do
  status, result = coroutine.resume(co, "B")
  print("!", status, result)
end

OUTPUT

1
2
3
4
5
!       true    A
?       1       B
6
7
8
9
!       true    A
?       1       B
10
11
12
13
!       true    A
?       1       B
14
15
!       true    nil
!       false   cannot resume dead coroutine

That's all.

fnuecke commented 10 years ago

You're talking about pre-emptive scheduling, and yes, this is something I considered (and promised someone to have another look into, so I'll leave this open as a reminder until I do). Some more details:

fnuecke commented 10 years ago

I had a look into this, and the main point of failure right now is that Eris doesn't support persisting coroutines yielded from hooks. I may have another look into this in the future, but not anytime soon I'm afraid.