[RETURN_ON_ERROR] Send to deep sleep withou imp.onidle()

Hey guys,

I need to put the Imp in deep sleep but I cannot use the callback imp.onidle() beacause I’m waiting for a server.connect() callback - which would be ignored if I put imp.deepsleepuntil() inside imp.onidle().

The code looks like this:
function execute() { if (hardware.wakereason() == WAKEREASON_TIMER) { pollAndEnqueue(); connectAndSend(); } else if (hardware.wakereason() == WAKEREASON_NEW_SQUIRREL) { // put in deep sleep } else if (hardware.wakereason() == WAKEREASON_POWER_ON) { // put in deep sleep } }
If I use imp.deepsleepuntil(…) in the place of “put in deep sleep”, I get the following error:
[Device] ERROR: sleeping in main program not recommended, see imp.onidle
Any suggestions on how to do this?