Skip to content

Commit

Permalink
Added function PNFuture.await() into new module pubnub-kotlin-corouti…
Browse files Browse the repository at this point in the history
…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
marcin-cebo and pubnub-release-bot authored Mar 7, 2025
1 parent cf4bd64 commit 46494e3
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 11 deletions.
13 changes: 9 additions & 4 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: kotlin
version: 10.4.4
version: 10.4.5
schema: 1
scm: github.com/pubnub/kotlin
files:
- build/libs/pubnub-kotlin-10.4.4-all.jar
- build/libs/pubnub-kotlin-10.4.5-all.jar
sdks:
-
type: library
Expand All @@ -23,8 +23,8 @@ sdks:
-
distribution-type: library
distribution-repository: maven
package-name: pubnub-kotlin-10.4.4
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-kotlin/10.4.4/pubnub-kotlin-10.4.4.jar
package-name: pubnub-kotlin-10.4.5
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-kotlin/10.4.5/pubnub-kotlin-10.4.5.jar
supported-platforms:
supported-operating-systems:
Android:
Expand Down Expand Up @@ -121,6 +121,11 @@ sdks:
license-url: https://www.apache.org/licenses/LICENSE-2.0.txt
is-required: Required
changelog:
- date: 2025-03-07
version: v10.4.5
changes:
- type: bug
text: "Internal fixes."
- date: 2025-03-07
version: v10.4.4
changes:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ You will need the publish and subscribe keys to authenticate your app. Get your
<dependency>
<groupId>com.pubnub</groupId>
<artifactId>pubnub-kotlin</artifactId>
<version>10.4.4</version>
<version>10.4.5</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RELEASE_SIGNING_ENABLED=true
SONATYPE_HOST=DEFAULT
SONATYPE_AUTOMATIC_RELEASE=false
GROUP=com.pubnub
VERSION_NAME=10.4.4
VERSION_NAME=10.4.5
POM_PACKAGING=jar

POM_NAME=PubNub SDK
Expand Down
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ cbor = { module = "co.nstant.in:cbor", version = "0.9" }
jetbrains-annotations = { module = "org.jetbrains:annotations", version = "24.1.0" }
kotlinx-atomicfu = { module = "org.jetbrains.kotlinx:atomicfu", version = "0.24.0" }
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx_datetime"}
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx_coroutines"}

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

# plugins for included build
kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
Expand Down
2 changes: 1 addition & 1 deletion pubnub-kotlin/pubnub-kotlin-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ kotlin {
dependencies {
implementation(project(":pubnub-kotlin:pubnub-kotlin-test"))
implementation(kotlin("test"))
implementation(libs.coroutines.test)
implementation(libs.kotlinx.coroutines.test)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pubnub-kotlin/pubnub-kotlin-core-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ kotlin {
dependencies {
implementation(project(":pubnub-kotlin:pubnub-kotlin-test"))
implementation(kotlin("test"))
implementation(libs.coroutines.test)
implementation(libs.kotlinx.coroutines.test)
}
}

Expand Down
15 changes: 15 additions & 0 deletions pubnub-kotlin/pubnub-kotlin-coroutines/build.gradle.kts
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)
}
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)
}
}
}
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class PubNubImplTest : BaseTest() {
fun getVersionAndTimeStamp() {
val version = PubNubImpl.SDK_VERSION
val timeStamp = PubNubImpl.timestamp()
assertEquals("10.4.4", version)
assertEquals("10.4.5", version)
assertTrue(timeStamp > 0)
}

Expand Down
2 changes: 1 addition & 1 deletion pubnub-kotlin/pubnub-kotlin-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ kotlin {
dependencies {
api(project(":pubnub-kotlin:pubnub-kotlin-api"))
api(kotlin("test"))
api(libs.coroutines.test)
api(libs.kotlinx.coroutines.test)
}
}

Expand Down
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ include("pubnub-kotlin")
include("pubnub-kotlin:pubnub-kotlin-core-api")
include("pubnub-kotlin:pubnub-kotlin-api")
include("pubnub-kotlin:pubnub-kotlin-impl")
include("pubnub-kotlin:pubnub-kotlin-coroutines")
include("pubnub-kotlin:pubnub-kotlin-test")
include("pubnub-gson")
include("pubnub-gson:pubnub-gson-api")
Expand All @@ -29,3 +30,4 @@ include("examples:kotlin-app")
include("examples:java-app")
includeBuild("build-logic/ktlint-custom-rules")
includeBuild("migration_utils")

0 comments on commit 46494e3

Please sign in to comment.