Jump to content




coroutine yeilding and sleep( )


  • You cannot reply to this topic
4 replies to this topic

#1 Exerro

  • Members
  • 801 posts

Posted 19 February 2013 - 11:19 AM

I'm making a multitasking thing where you load processes and they create windows and each file can have its own process and if you use term.write / term.clear in that file it saves it to a screen table for the files processes window
( window.s[process.running[shell.getRunningProgram()].window].screen ) i think. Any way, it all works fine and prints to the screen through the screen table and a drawScreen function but i want the program being run to sleep but that always stops the code completely
sleep and coroutine.yeild make the program stop and os.pullEvent and a timer dont do a thing and pause it for about a millisecond maybe

Is there a way to pause code when its being run through a coroutine?

My code ( with comments ) :
Spoiler


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 19 February 2013 - 11:41 AM

Why in the hell are you running your coroutine in a for loop and not giving it events? A coroutine management loop is a while loop, and looks vaguely thus:

while true do
  event = {coroutine.yield()}
  coroutine.resume(myCoroutine, unpack(event))
end

Take a look at how the parallel API manages its coroutines. I guarantee you it isn't a for loop.

#3 Exerro

  • Members
  • 801 posts

Posted 19 February 2013 - 12:16 PM

yes this is nowhere near finished i was just testing how it behaved, the for loop is just because i have no way to terminate a while loop
my problem is the code not pausing at the os.pull event and stopping if i call sleep

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 19 February 2013 - 12:59 PM

That's because your coroutine manager isn't behaving like it should. Fix the coroutine manager to do what it should, because that is why you are seeing the behavior you are. Your coroutine yields and then the manager resumes it a tenth of a second later, because that's exactly what you are telling it to do.

#5 Exerro

  • Members
  • 801 posts

Posted 19 February 2013 - 01:06 PM

ah so sleep doesnt sleep for how long you put in, it just yeilds then the coroutine is resumed straight after so it makes no difference?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users