This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Wojbie's profile picture

Need a bit help about advanced event handling.

Started by Wojbie, 16 May 2014 - 07:16 PM
Wojbie #1
Posted 16 May 2014 - 09:16 PM
I am writing a redirect object for Computercraft that will send term requests to webserver using http api in order to be processed there. But i got a little bit of logic problem.
In order to do that i need to do http.request and then yeld waiting for "http_success" or "http_failure" events - that means if there was a timer or there is any rednet message it will get "eaten" by term call - similar to how turtle movement eats events. I am trying to make it behave exactly like term api so it should not do that.
I had idea to store all events and then re-queue them after i get what i needed but that would duplicate events in parallel environment (like parallel api or multi-shell) due to queueEvent queuing them for whole chain.
Does anyone got idea how to make it act like i want it to act? As in not eat events while still yielding for needed event? Or is there no way to make it do what i need it to do?
KingofGamesYami #2
Posted 16 May 2014 - 10:04 PM
I am writing a redirect object for Computercraft that will send term requests to webserver using http api in order to be processed there. But i got a little bit of logic problem.
In order to do that i need to do http.request and then yeld waiting for "http_success" or "http_failure" events - that means if there was a timer or there is any rednet message it will get "eaten" by term call - similar to how turtle movement eats events. I am trying to make it behave exactly like term api so it should not do that.
I had idea to store all events and then re-queue them after i get what i needed but that would duplicate events in parallel environment (like parallel api or multi-shell) due to queueEvent queuing them for whole chain.
Does anyone got idea how to make it act like i want it to act? As in not eat events while still yielding for needed event? Or is there no way to make it do what i need it to do?

If I understand what you are asking here, you could overwrite os.pullEventRaw()

basically:

oldPull = os.pullEventRaw

function os.pullEventRaw(...)
    event = oldPull(...)
    if event[1] == ??? then --#insert event to capture here
      --do what you want to do
    end --# alternatively, you can insert more else/if statements, even modifing the event that will be returned
    return event
end
An example of using this would be to convert a button api for terminals to work on monitors. Simply generate a valid "mouse_click" event whenever a "monitor_touch" event is received.
Wojbie #3
Posted 16 May 2014 - 10:31 PM
I have thought of that - and instead of yielding return event form history until history table is empty - that however again gets in the way of parrarel and coroutine stuff. That would also effect in getting close to getting "Too long without yelding error". I think i am overthinking this. I need to sleep this over.