Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setOnBackgroundMessage not getting along with async/await #496

Closed
asoap opened this issue Nov 15, 2023 · 4 comments
Closed

setOnBackgroundMessage not getting along with async/await #496

asoap opened this issue Nov 15, 2023 · 4 comments

Comments

@asoap
Copy link
Contributor

asoap commented Nov 15, 2023

When getting a background notification while the app is in a dead state. I can see Ably launching the app and I see the background notification execute. But I'm having an odd issue where I want to do a few things. Like updating some counters in stored local storage and updating the app's badge icon. All of these which use asyn/await to know when to continue. I investigate the code execution on Android using logcat I see the app dying before the function completes.

I see the app waking, I see it login via our webserver getting it's ably token, connecting to ably, and then getting the background message. It then starts executing the background message only for it to stop when it gets to an await. Under my normal code it was kind of a mix on which await would cause it to stop. Some awaits would execute, others would end the function. So I created a test to confirm it wasn't me.

ably.Push.notificationEvents.setOnBackgroundMessage(StateTestNotification.backgroundMessageHandler);

class StateTestNotification {
  static Future<void> backgroundMessageHandler(ably.RemoteMessage message) async {
    print('---------------- Just received a background message, with:');
    print('RemoteMessage.Data: ${message.data.toString()}');
    bool delayResult = await Future.delayed(Duration(milliseconds: 1), () {
      return true;
    });
    print('delay result: $delayResult');
    print('at end of backgroundMessageHandler');
  }
}

When I look at the logs using logcat I see:

---------------- Just received a background message, with:
RemoteMessage.Data: {increment: {"mydata": "here"}}

The rest of the prints() are missing. It always dies when it sees a delay of one millisecond.
Is there any way around this? Am I doing something wrong?

Copy link

sync-by-unito bot commented Nov 15, 2023

➤ Automation for Jira commented:

The link to the corresponding Jira issue is https://ably.atlassian.net/browse/SDK-3946

@asoap
Copy link
Contributor Author

asoap commented Nov 30, 2023

I managed to fix this. I've created a pull request which you can find here:
#498

@stmoreau
Copy link

stmoreau commented Dec 4, 2023

Thank you for raising this and for sending over your PR @asoap. We'll get back to you on it very shortly 😄

@ttypic
Copy link
Contributor

ttypic commented Dec 14, 2023

Fixed in #499

@ttypic ttypic closed this as completed Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants