Waiting until event response

Hi All,

My code part is below.

I want to wait my code until to network listener event to response.

I am trying to dump while but no response back.

How can i wait my code in for statement?

Thanks in advice.

[lua]local downStatu== 0

local function networkListener( event )
if ( event.isError ) then
downStatu=1
else
downStatu=2
downResponse=event.response
end
end

for row 1, 10 do
downStatu=0
network.request( url, “GET”, networkListener )

while downStatu == 0 do
–I want to wait until downStatu will be 2
end

–do something and goto next row
end [/lua]

There is no way (that I know) to pause a for loop.

You can use 2 functions that call each other, something like this:

[lua]

local func= nil

local listener= nil

int i = 0

listener = function(event)

if (!event.error and i < 10) then

func()

i = i + 1

end

end

func = function()

network.request(url, “GET”, listener)

end

[/lua]

Daniel

You don’t ; you wait for a response or for it to time out. You need to read up on the differences between event driven programming and ‘normal’ sequential programming

thank you so much Daniel  :) 

Remember 1 thing, never use ‘while’ for events. Corona is only one thread application so you will freeze your app. What’s more, if it freezes thrn it won’t be able to receive network event.

There is no way (that I know) to pause a for loop.

You can use 2 functions that call each other, something like this:

[lua]

local func= nil

local listener= nil

int i = 0

listener = function(event)

if (!event.error and i < 10) then

func()

i = i + 1

end

end

func = function()

network.request(url, “GET”, listener)

end

[/lua]

Daniel

You don’t ; you wait for a response or for it to time out. You need to read up on the differences between event driven programming and ‘normal’ sequential programming

thank you so much Daniel  :) 

Remember 1 thing, never use ‘while’ for events. Corona is only one thread application so you will freeze your app. What’s more, if it freezes thrn it won’t be able to receive network event.