Improve Envelope Caching process
Description
As of now we save envelopes to disk right before try to send them. In case of a slow network connection this could lead to envelopes queuing up and being potentially lost in case of an app termination.
We should try to store to disk as early as possible, and then enqueue the envelope for sending over the wire.
Kind of related to https://github.com/getsentry/sentry-java/issues/2733 to use priority queue for sending/storing
The logic of the Cocoa SDK is simple. When there is a new envelope, the SDK first stores it to disk async. We accept the tradeoff that we might lose some envelopes, over blocking the calling thread, which could be the main thread. Then the SDK sends all stored envelopes one after the other, which is our queue. Then it sends the oldest envelope, once its out, it deletes it, and continues with the next one.
All the logic is in SentryHttpTransport:
https://github.com/getsentry/sentry-cocoa/blob/02a972c0ca0bf376a9ad425d317596827380e9ad/Sources/Sentry/SentryHttpTransport.m#L130-L138