Priority of Particle.function return vs. Particle.publish

Sometimes, my mobile gets Particle.function return and Particle.publish event in reversed (ie. unexpected) order.

  1. Mobile calls Electron Particle.function
  2. Electron Particle.function raise a flag, then returns a number.
  3. Electron loop() see flag and does Particle.publish.
  4. mobile gets the return next.
  5. Then mobile gets the Pariticle.publish event.

Problem is sometimes:
4. mobile gets the Pariticle.publish event
5. mobile gets the return next

BACKGROUND:
Mobile calls Particle.function to tell Electron to publish a record.
Electron normally responds to function by returning number of the record to be published, and then Electron publishes the record.
Normally, mobile gets return value = record number, and then gets publication of record, and can then verify expected record number.

So, what is your question? I’ve seen the same thing. I don’t think this has anything to do with priority, since which comes first seems to be indeterminate. I think it’s more likely due to the function return and the publish request being handled by different processes on the Particle servers that may have different delays based on how busy they are. If it’s important to your app that you get them in the expected order, then you might want to call the function twice with different arguments. For instance, you call it once with “1” as the argument. The function handler returns the record number, based on an if-else clause that tests the argument value. In the completion handler for the function call in your mobile app, you call the same function again but with “2” this time. The function handler then sets the flag to initiate the publish in loop.

Thanks, you answered it: “indeterminate”.