Coalescing Task Runner With Result
A coroutine-based utility that coalesces multiple invocations of a suspending task and ensures only the latest scheduled invocation is executed, returning its result.
This is useful in scenarios where a task may be triggered frequently (e.g., UI events, network polling), but only the most recent execution and its result are relevant.
Example use case: auto-refreshing data on user input where intermediate results can be discarded.
The task is executed on a dedicated coroutine scope with optional error handling. If a task is currently running and a new one is scheduled, the new task supersedes previous pending triggers but waits for its result.
Parameters
Coroutine context to run the task (defaults to Dispatchers.Default).
The suspending function to execute. Only one instance runs at a time.
The result type of the task.