-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added function PNFuture.await() #338
Conversation
as a convenient function for those users that use coroutines. New module pubnub-kotlin-coroutines has been created.
import kotlin.coroutines.resumeWithException | ||
|
||
suspend fun <T> PNFuture<T>.await(): T { | ||
val t = suspendCancellableCoroutine { cont -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: t
isn't needed, I'd just do suspend fun <T> PNFuture<T>.await(): T = suspendCancellableCoroutine { ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I will change it.
|
||
class UtilKtTest { | ||
@Test | ||
fun `await returns result on success`() = runBlocking { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use runTest
from kotlinx-coroutines-test instead of runBlocking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
import org.junit.jupiter.api.Test | ||
import kotlin.test.assertFailsWith | ||
|
||
class FakePNFuture<T>(private val block: (Consumer<com.pubnub.api.v2.callbacks.Result<T>>) -> Unit) : PNFuture<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't really need it, I think you should be able to just do :
Unit.asFuture().then { error("exception!") }
or
expected.asFuture()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
settings.gradle.kts
Outdated
@@ -29,3 +29,4 @@ include("examples:kotlin-app") | |||
include("examples:java-app") | |||
includeBuild("build-logic/ktlint-custom-rules") | |||
includeBuild("migration_utils") | |||
include("pubnub-kotlin-coroutines") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would maybe put it in the pubnub-kotlin
directory, but it's not critical, I think when you release it to maven the end result is the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@pubnub-release-bot release kotlin as v10.4.5 |
🚀 Release successfully completed 🚀 |
fix: Internal fixes.