commit | 9791b89702e0cdf95bbc4459ce2351c8305dd674 | [log] [tgz] |
---|---|---|
author | Renaud Paquay <rpaquay@google.com> | Thu Apr 18 12:51:32 2024 -0700 |
committer | Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> | Wed Apr 24 14:59:24 2024 +0000 |
tree | 8425f2fc407ef7461e7edd189cf4ed86fade06ba | |
parent | a87ca2b9e4ade87b92eca815b497e7254d5bdf1b [diff] |
adblib: Add `runAlongOtherScope` utility It is sometimes useful to run a coroutine function (i.e. a `suspend` function) that should be cancelled from 2 possible sources: either the cancellation can come from the the current scope (or parent), or the cancellation can come with some other unrelated scope with an unrelated lifetime. In the context of `adblib`, this can be useful when executing a long running coroutine, e.g. collecting a `StateFlow`, for a long as a device is connected or for as long as a JdwpProcess is active. By using the `ConnectedDevice.scope` or `JdwpProcess.scope` as the `otherScope` parameter of `runAlongOtherScope`, one can achieve the intended behavior. Note that the using the `outerScope.async { suspend_call() }.await` pattern does not quite work: cancellation of `outerScope` indeed ensures that `suspend_call()` is cancelled, but cancellation of the parent scope only cancel the `await()` call, i.e. it does *not* cancel the `suspend_call()` coroutine. Test: Included Bug: n/a Change-Id: I3982def486b1f9712500001881df5d1e03fa7b32
This project contains: