Code doesn't continue to execute when server.connect(..) is used with RETURN_ON_ERROR

Hi,
I’m using RETURN_ON_ERROR policy as described on http://electricimp.com/docs/resources/offline/
in my code I’m doing something like this
server.connect(disconnection_handler,30);
server_log(LOW,"time to sample "+ (end-start)) ;
this.upload_samples();
my program flow sequence is : disconnecting the device -> read samples -> connect the device -> upload samples -> sleep
so here when used with RETURN_ON_ERROR, after server.connect(…) it goes into the callback function. but doesn’t come back and upload the samples.
In a normal execution I’d expect it to go into callback function, then return back to normal operation.

Server.connect is a background call; your code continues to run whilst the connection is in progress. In your code example above, you kick off the connection attempt, but then immediately try to load and upload samples, both of which will just return an error because there is no connection yet.

You should call upload_samples() from the callback (which you’ve called “disconnection_handler” here?) when it is called with the parameter “SERVER_CONNECTED”.