Reputation: 11
Some background reading at first :) what is shutdown handling
I'm doing a custom receiver with CAF SDK.
With the similar shutdown handling, I try to dispatch some http requests within the callback like:
receiver.addEventListener(
cast.framework.system.EventType.SHUTDOWN,
e => {
// some http requests
HttpHandler.post(url, somePayload);
HttpHandler.post(anotherUrl, someOtherPayload);
....... (more requests to go)
});
However, I can't guarantee those requests are reaching the destination since the receiver application is about to terminate anytime(Likely less than 1 sec).Those requests were also proved not reaching the destination in fact.
As far as I know, there is no way to postpone the shutdown of the receiver application with CAF SDK itself.
Is there a workaround about it? Is there a way we can postpone shutdown with the help of CAF SDK?
Upvotes: 1
Views: 388
Reputation: 56
I did some more research, and it turns out you can also use
window.addEventListener("beforeunload", e => {
...
});
instead of
receiver.addEventListener(
cast.framework.system.EventType.SHUTDOWN,
e => {
...
});
Alas, this does not help to assure everything in the callback is executed: the beforeunload callback is terminated in the same way as the shutdown handler.
Upvotes: 1
Reputation: 11
The answer seems quite simple: turn all http requests to synchronous.
Drawbacks are quite obvious as well, synchronous requests will block the thread. When one request is hung in middle of somewhere due to unknown reasons, the script will be blocked forever unless force shutdown.
Still looking for better way to improve it.
Upvotes: 0