So I am trying to make my app check if it should load data after Resuming the app. On resume it has to execute a callback to App42.
When It resumes it reaches the point where it prints : (“I’m in, yes!!”). If I suspend the app…the CallBack continues and I get the data I need. But it is too late. I want the data on Resuming.
It is weird, sometimes (rarely) it works and I get the data on Resume. It looks like when trying to execute the App42 API ,it just blocks the execution.
I have been reading about coroutines and yielding but I am totally lost.
What is happening? How can I fix it?
elseif (event.type == "applicationResume" )then local function updatedgamesFetch(event) if event ~= 404 and event then local gamesupdatedtable = event if table.indexOf(gamesupdatedtable, docId) then print("load data from app42") end end end utility.checkupdatedgames(updatedgamesFetch,localplayer) print("Application resumed from suspension") end end
Checkupdatedgames looks like this
function M.checkupdatedgames(returnHandler,localplayer) if ( returnHandler and type(returnHandler) == "function" ) then M.callback = returnHandler else error( "No callback function listed" ) end local q1 = queryBuilder:build("localplayer",localplayer,Operator.NOT\_EQUALS) local q2 = queryBuilder:build("uid1",localplayer,Operator.EQUALS) local q3 = queryBuilder:build("uid2",localplayer,Operator.EQUALS) local queryI = queryBuilder:compoundOperator(q2,Operator.OR,q3) local query = queryBuilder:compoundOperator(queryI,Operator.AND,q1) print("I'm in, yes!!") local App42CallBack3= {} local gamesupdatedtable ={} storageService2:findDocumentsByQuery(dbName, collectionName,query,App42CallBack3) function App42CallBack3:onSuccess(object) print("I'm inside onSuccess") for i=1,table.getn(object:getJsonDocList()) do print("DocId is "..object:getJsonDocList()[i]:getDocId()) table.insert(gamesupdatedtable,object:getJsonDocList()[i]:getDocId()) end M.callback(gamesupdatedtable) end function App42CallBack3:onException(exception) print("I'm inside the Exception") print("Message is : "..exception:getMessage()) print("App Error code is : "..exception:getAppErrorCode()) print("Http Error code is "..exception:getHttpErrorCode()) print("Detail is : "..exception:getDetails()) M.callback(exception:getHttpErrorCode()) end end

