Wait for End of performWithDelay

Hi guys.

I have a little problem and i hope someone can help me or tell me a thread with a solution. I cannot find something about my problem.

I’have two files. One File is a modula Class (portal):

local t = {}  
function t:timer(event)  
 local params = {}  
 params.body = '...'  
 local count = event.count  
 network.request( server .. '/somerequest', "POST", networkListener , params)  
 if someValue ~= nil then -- someValue is changed in networkListener  
 timer.cancel(event.source)  
 end  
end  
  
function portal.getPartner()  
 if(nick ~= nil) then  
 if(sessionId == nil) then  
 timer.performWithDelay(2000,t, 15)  
 end  
 end  
end  

In the second file (main) i’m calling getPartner from portal-class like:

print("pre")  
portal.getPartner()  
print("post")  

is there a way to wait for the end of the delayed Function.
Only to show you what i mean, i want to have that “pre” is printed and “post” is printed after the timer funktion has ended.

I hope you understand what i want to to and someone can tell me how to get this running

Thanks [import]uid: 189020 topic_id: 34325 reply_id: 334325[/import]

I would suspect you need to do whatever you want to do after the timer fires in your ‘networkListener’ function that network.request() is going to call back to when it completes its request and there is where you would print your “Post” message.
[import]uid: 199310 topic_id: 34325 reply_id: 136460[/import]

If I just want to print something that would work. But the print should serve only as an example. I want the main waiting until the delay got the correct answer or tried 15 times to get the answer.

the main calls the “getpartner” and then the main should wait. but the main is going on after starting the timer.

is there something like

repeat  
 DONOTHING  
until( timer.getState == stopped)   

what i can use in the main.lua?

[import]uid: 189020 topic_id: 34325 reply_id: 136567[/import]

network.request() and it’s sibling functions, as well as timer.performWithDelay() are asynchronous functions. That is they fire off a background process and return immediately to your program’s flow. When they finish (not timer.performWithDelay since it doesn’t call back to your program) they interrupt your game by calling a function known as a “callBack” function. This is where your program is supposed to handle the results of the background operation and then return to the flow of your game.

Only in these “onComplete” or “networkListner” function (we have several different names we call them) will your program know the process is complete and can then go off and do things.

Attempting to write a busy-wait loop like your repeat, is only going to kill your performance, drain your battery life. Corona will handle the “waiting” so in your example, you really don’t need to do anything after you call your portal.getPartner() code in main. Just make sure your “networkListener” function can pick up the program flow once that completes.
[import]uid: 199310 topic_id: 34325 reply_id: 136594[/import]

I would suspect you need to do whatever you want to do after the timer fires in your ‘networkListener’ function that network.request() is going to call back to when it completes its request and there is where you would print your “Post” message.
[import]uid: 199310 topic_id: 34325 reply_id: 136460[/import]

If I just want to print something that would work. But the print should serve only as an example. I want the main waiting until the delay got the correct answer or tried 15 times to get the answer.

the main calls the “getpartner” and then the main should wait. but the main is going on after starting the timer.

is there something like

repeat  
 DONOTHING  
until( timer.getState == stopped)   

what i can use in the main.lua?

[import]uid: 189020 topic_id: 34325 reply_id: 136567[/import]

network.request() and it’s sibling functions, as well as timer.performWithDelay() are asynchronous functions. That is they fire off a background process and return immediately to your program’s flow. When they finish (not timer.performWithDelay since it doesn’t call back to your program) they interrupt your game by calling a function known as a “callBack” function. This is where your program is supposed to handle the results of the background operation and then return to the flow of your game.

Only in these “onComplete” or “networkListner” function (we have several different names we call them) will your program know the process is complete and can then go off and do things.

Attempting to write a busy-wait loop like your repeat, is only going to kill your performance, drain your battery life. Corona will handle the “waiting” so in your example, you really don’t need to do anything after you call your portal.getPartner() code in main. Just make sure your “networkListener” function can pick up the program flow once that completes.
[import]uid: 199310 topic_id: 34325 reply_id: 136594[/import]