mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-03-17 21:31:57 +01:00
Moves to using cancellable coroutines to avoid cancelling the parent group all together.
This commit is contained in:
parent
160d4722c0
commit
a09b8c5862
@ -23,10 +23,10 @@ package com.vitorpamplona.amethyst
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.joinAll
|
||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import kotlin.coroutines.Continuation
|
||||
import kotlin.coroutines.resume
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
|
||||
/**
|
||||
* Launches an async coroutine for each item, runs the
|
||||
@ -59,7 +59,7 @@ suspend inline fun <T> tryAndWait(
|
||||
crossinline asyncFunc: (Continuation<T>) -> Unit,
|
||||
): T? =
|
||||
withTimeoutOrNull(timeoutMillis) {
|
||||
suspendCoroutine { continuation ->
|
||||
suspendCancellableCoroutine { continuation ->
|
||||
asyncFunc(continuation)
|
||||
}
|
||||
}
|
||||
|
@ -35,11 +35,11 @@ import com.vitorpamplona.amethyst.ui.components.util.MediaCompressorFileUtils
|
||||
import id.zelory.compressor.Compressor
|
||||
import id.zelory.compressor.constraint.default
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import java.io.File
|
||||
import java.util.UUID
|
||||
import kotlin.coroutines.resume
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
|
||||
class MediaCompressorResult(
|
||||
val uri: Uri,
|
||||
@ -94,7 +94,7 @@ class MediaCompressor {
|
||||
|
||||
val result =
|
||||
withTimeoutOrNull(30000) {
|
||||
suspendCoroutine { continuation ->
|
||||
suspendCancellableCoroutine { continuation ->
|
||||
VideoCompressor.start(
|
||||
// => This is required
|
||||
context = applicationContext,
|
||||
|
@ -44,9 +44,9 @@ import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.joinAll
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import kotlin.coroutines.resume
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
|
||||
@Stable
|
||||
open class NewMediaModel : ViewModel() {
|
||||
@ -138,7 +138,7 @@ open class NewMediaModel : ViewModel() {
|
||||
// upload each file as an individual nip95 event.
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
withTimeoutOrNull(30000) {
|
||||
suspendCoroutine { continuation ->
|
||||
suspendCancellableCoroutine { continuation ->
|
||||
account?.createNip95(it.bytes, headerInfo = it.fileHeader, caption, sensitiveContent) { nip95 ->
|
||||
account?.consumeAndSendNip95(nip95.first, nip95.second, relayList)
|
||||
continuation.resume(true)
|
||||
@ -153,7 +153,7 @@ open class NewMediaModel : ViewModel() {
|
||||
// upload each file as an individual nip95 event.
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
withTimeoutOrNull(30000) {
|
||||
suspendCoroutine { continuation ->
|
||||
suspendCancellableCoroutine { continuation ->
|
||||
account?.sendHeader(
|
||||
it.url,
|
||||
it.magnet,
|
||||
@ -174,7 +174,7 @@ open class NewMediaModel : ViewModel() {
|
||||
listOf(
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
withTimeoutOrNull(30000) {
|
||||
suspendCoroutine { continuation ->
|
||||
suspendCancellableCoroutine { continuation ->
|
||||
account?.sendAllAsOnePictureEvent(
|
||||
imageUrls,
|
||||
caption,
|
||||
|
Loading…
x
Reference in New Issue
Block a user