Skip to content

Commit 46494e3

Browse files
Added function PNFuture.await() into new module pubnub-kotlin-coroutines (#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]>
1 parent cf4bd64 commit 46494e3

File tree

13 files changed

+86
-11
lines changed

13 files changed

+86
-11
lines changed

.pubnub.yml

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: kotlin
2-
version: 10.4.4
2+
version: 10.4.5
33
schema: 1
44
scm: github.com/pubnub/kotlin
55
files:
6-
- build/libs/pubnub-kotlin-10.4.4-all.jar
6+
- build/libs/pubnub-kotlin-10.4.5-all.jar
77
sdks:
88
-
99
type: library
@@ -23,8 +23,8 @@ sdks:
2323
-
2424
distribution-type: library
2525
distribution-repository: maven
26-
package-name: pubnub-kotlin-10.4.4
27-
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-kotlin/10.4.4/pubnub-kotlin-10.4.4.jar
26+
package-name: pubnub-kotlin-10.4.5
27+
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-kotlin/10.4.5/pubnub-kotlin-10.4.5.jar
2828
supported-platforms:
2929
supported-operating-systems:
3030
Android:
@@ -121,6 +121,11 @@ sdks:
121121
license-url: https://www.apache.org/licenses/LICENSE-2.0.txt
122122
is-required: Required
123123
changelog:
124+
- date: 2025-03-07
125+
version: v10.4.5
126+
changes:
127+
- type: bug
128+
text: "Internal fixes."
124129
- date: 2025-03-07
125130
version: v10.4.4
126131
changes:

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v10.4.5
2+
March 07 2025
3+
4+
#### Fixed
5+
- Internal fixes.
6+
17
## v10.4.4
28
March 07 2025
39

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ You will need the publish and subscribe keys to authenticate your app. Get your
2020
<dependency>
2121
<groupId>com.pubnub</groupId>
2222
<artifactId>pubnub-kotlin</artifactId>
23-
<version>10.4.4</version>
23+
<version>10.4.5</version>
2424
</dependency>
2525
```
2626

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ RELEASE_SIGNING_ENABLED=true
1818
SONATYPE_HOST=DEFAULT
1919
SONATYPE_AUTOMATIC_RELEASE=false
2020
GROUP=com.pubnub
21-
VERSION_NAME=10.4.4
21+
VERSION_NAME=10.4.5
2222
POM_PACKAGING=jar
2323

2424
POM_NAME=PubNub SDK

gradle/libs.versions.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ cbor = { module = "co.nstant.in:cbor", version = "0.9" }
2727
jetbrains-annotations = { module = "org.jetbrains:annotations", version = "24.1.0" }
2828
kotlinx-atomicfu = { module = "org.jetbrains.kotlinx:atomicfu", version = "0.24.0" }
2929
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx_datetime"}
30+
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx_coroutines"}
3031

3132
# tests
3233
wiremock = { module = "com.github.tomakehurst:wiremock", version = "2.27.2" }
@@ -44,7 +45,7 @@ mockk = { module = "io.mockk:mockk", version = "1.11.0" }
4445
owner = { module = "org.aeonbits.owner:owner", version = "1.0.12" }
4546
mockito = { module = "org.mockito:mockito-core", version = "4.8.1" }
4647
hamcrest = { module = "org.hamcrest:hamcrest-all", version = "1.3" }
47-
coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx_coroutines"}
48+
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx_coroutines"}
4849

4950
# plugins for included build
5051
kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }

pubnub-kotlin/pubnub-kotlin-api/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ kotlin {
5858
dependencies {
5959
implementation(project(":pubnub-kotlin:pubnub-kotlin-test"))
6060
implementation(kotlin("test"))
61-
implementation(libs.coroutines.test)
61+
implementation(libs.kotlinx.coroutines.test)
6262
}
6363
}
6464

pubnub-kotlin/pubnub-kotlin-core-api/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ kotlin {
3939
dependencies {
4040
implementation(project(":pubnub-kotlin:pubnub-kotlin-test"))
4141
implementation(kotlin("test"))
42-
implementation(libs.coroutines.test)
42+
implementation(libs.kotlinx.coroutines.test)
4343
}
4444
}
4545

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
plugins {
2+
alias(libs.plugins.benmanes.versions)
3+
id("pubnub.kotlin-library")
4+
id("pubnub.dokka")
5+
id("pubnub.shared")
6+
}
7+
8+
dependencies {
9+
api(project(":pubnub-kotlin:pubnub-kotlin-api"))
10+
api(libs.kotlinx.coroutines.core)
11+
implementation(kotlin("test"))
12+
testImplementation(libs.kotlinx.coroutines.test)
13+
testImplementation(libs.junit.jupiter.engine)
14+
testImplementation(libs.junit.jupiter)
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.pubnub.coroutines
2+
3+
import com.pubnub.kmp.PNFuture
4+
import kotlinx.coroutines.suspendCancellableCoroutine
5+
import kotlin.coroutines.resume
6+
import kotlin.coroutines.resumeWithException
7+
8+
suspend fun <T> PNFuture<T>.await(): T =
9+
suspendCancellableCoroutine { cont ->
10+
async { result ->
11+
result.onSuccess {
12+
cont.resume(it)
13+
}.onFailure {
14+
cont.resumeWithException(it)
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.pubnub.coroutines
2+
3+
import com.pubnub.kmp.asFuture
4+
import com.pubnub.kmp.then
5+
import kotlinx.coroutines.test.runTest
6+
import org.junit.jupiter.api.Assertions.assertEquals
7+
import org.junit.jupiter.api.Test
8+
import kotlin.test.assertFailsWith
9+
10+
class UtilKtTest {
11+
@Test
12+
fun `await returns result on success`() = runTest {
13+
val expected = "Success Result"
14+
assertEquals(expected, expected.asFuture().await())
15+
}
16+
17+
@Test
18+
fun `await throws exception on failure`() = runTest {
19+
val exception = Exception("Failure occurred")
20+
21+
val future = exception.asFuture().then { throw it }
22+
// When await() is called, it should resume with an exception.
23+
val thrown = assertFailsWith<Exception> {
24+
future.await()
25+
}
26+
// Optionally verify the exception message.
27+
assertEquals(exception.message, thrown.message)
28+
}
29+
}

pubnub-kotlin/pubnub-kotlin-impl/src/test/kotlin/com/pubnub/api/legacy/PubNubImplTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class PubNubImplTest : BaseTest() {
5656
fun getVersionAndTimeStamp() {
5757
val version = PubNubImpl.SDK_VERSION
5858
val timeStamp = PubNubImpl.timestamp()
59-
assertEquals("10.4.4", version)
59+
assertEquals("10.4.5", version)
6060
assertTrue(timeStamp > 0)
6161
}
6262

pubnub-kotlin/pubnub-kotlin-test/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ kotlin {
1616
dependencies {
1717
api(project(":pubnub-kotlin:pubnub-kotlin-api"))
1818
api(kotlin("test"))
19-
api(libs.coroutines.test)
19+
api(libs.kotlinx.coroutines.test)
2020
}
2121
}
2222

settings.gradle.kts

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ include("pubnub-kotlin")
2121
include("pubnub-kotlin:pubnub-kotlin-core-api")
2222
include("pubnub-kotlin:pubnub-kotlin-api")
2323
include("pubnub-kotlin:pubnub-kotlin-impl")
24+
include("pubnub-kotlin:pubnub-kotlin-coroutines")
2425
include("pubnub-kotlin:pubnub-kotlin-test")
2526
include("pubnub-gson")
2627
include("pubnub-gson:pubnub-gson-api")
@@ -29,3 +30,4 @@ include("examples:kotlin-app")
2930
include("examples:java-app")
3031
includeBuild("build-logic/ktlint-custom-rules")
3132
includeBuild("migration_utils")
33+

0 commit comments

Comments
 (0)