A solution is not to cancel the flow, but the Job returned from launching the flow in a scope.
val job = scope.launch { flow.cancellable().collect { } }
job.cancel()
NOTE: cancellable() will ensure the flow is terminated before new items are emitted to collect { } if its job is cancelled, though flow builder and all implementations of SharedFlow are cancellable() by default.