Best way to handle async background task (MQTT client)

I’m building an Ionic app which has to interact with an MQTT broker.
My concern is: where is the best place to handle the MQTT client?

If i put it on a page, the result will be that the MQTT client will work only when the page is displayed, so some messages can be lost if are delivered while the page is not displayed.

Which is the best way to handle in an Ionic app something like that? Using a web worker could be a solution?

put it in an provider. Those will live long enough to tell the tale

1 Like

I agree with @Tommertom re: Ionic 3. The fancy new technology, though, is that Stencil components use web workers by default. So if you can build that piece in Stencil (for Ionic 4, or 100% pure Stencil), then you’ll get advanced structure for free. In Ionic 3, you can build a web worker into your provider, which isn’t hard-hard, but it will take a bit more work.

1 Like

Have you looked at: