-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added function PNFuture.await() into new module pubnub-kotlin-corouti…
…nes (#338) * Added function PNFuture.await() into new module pubnub-kotlin-coroutines as a convenient function for those users that use coroutines. New module will be release as separate artefact. * PubNub SDK v10.4.5 release. --------- Co-authored-by: PubNub Release Bot <[email protected]>
- Loading branch information
1 parent
cf4bd64
commit 46494e3
Showing
13 changed files
with
86 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
## v10.4.5 | ||
March 07 2025 | ||
|
||
#### Fixed | ||
- Internal fixes. | ||
|
||
## v10.4.4 | ||
March 07 2025 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
plugins { | ||
alias(libs.plugins.benmanes.versions) | ||
id("pubnub.kotlin-library") | ||
id("pubnub.dokka") | ||
id("pubnub.shared") | ||
} | ||
|
||
dependencies { | ||
api(project(":pubnub-kotlin:pubnub-kotlin-api")) | ||
api(libs.kotlinx.coroutines.core) | ||
implementation(kotlin("test")) | ||
testImplementation(libs.kotlinx.coroutines.test) | ||
testImplementation(libs.junit.jupiter.engine) | ||
testImplementation(libs.junit.jupiter) | ||
} |
17 changes: 17 additions & 0 deletions
17
pubnub-kotlin/pubnub-kotlin-coroutines/src/main/kotlin/com/pubnub/coroutines/Util.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.pubnub.coroutines | ||
|
||
import com.pubnub.kmp.PNFuture | ||
import kotlinx.coroutines.suspendCancellableCoroutine | ||
import kotlin.coroutines.resume | ||
import kotlin.coroutines.resumeWithException | ||
|
||
suspend fun <T> PNFuture<T>.await(): T = | ||
suspendCancellableCoroutine { cont -> | ||
async { result -> | ||
result.onSuccess { | ||
cont.resume(it) | ||
}.onFailure { | ||
cont.resumeWithException(it) | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
pubnub-kotlin/pubnub-kotlin-coroutines/src/test/kotlin/com/pubnub/coroutines/UtilKtTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.pubnub.coroutines | ||
|
||
import com.pubnub.kmp.asFuture | ||
import com.pubnub.kmp.then | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
import kotlin.test.assertFailsWith | ||
|
||
class UtilKtTest { | ||
@Test | ||
fun `await returns result on success`() = runTest { | ||
val expected = "Success Result" | ||
assertEquals(expected, expected.asFuture().await()) | ||
} | ||
|
||
@Test | ||
fun `await throws exception on failure`() = runTest { | ||
val exception = Exception("Failure occurred") | ||
|
||
val future = exception.asFuture().then { throw it } | ||
// When await() is called, it should resume with an exception. | ||
val thrown = assertFailsWith<Exception> { | ||
future.await() | ||
} | ||
// Optionally verify the exception message. | ||
assertEquals(exception.message, thrown.message) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters