daily pastebin goal
45%
SHARE
TWEET

Untitled

a guest Mar 24th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package sample
  2.  
  3. import kotlinx.coroutines.*
  4. import kotlin.coroutines.CoroutineContext
  5. import kotlin.coroutines.EmptyCoroutineContext
  6. import kotlin.js.Promise
  7. import kotlin.test.Test
  8. import kotlin.test.assertEquals
  9.  
  10. class PromiseSampleTest {
  11.     @Test
  12.     fun testHelloAsync() = async {
  13.         val result = getAsyncData().await()
  14.         assertEquals(result, "Hello")
  15.     }
  16.  
  17.     private fun getAsyncData(): Promise<String> {
  18.         return Promise.resolve("Hello")
  19.     }
  20. }
  21.  
  22. fun <T> async(
  23.     context: CoroutineContext = EmptyCoroutineContext,
  24.     start: CoroutineStart = CoroutineStart.DEFAULT,
  25.     block: suspend CoroutineScope.() -> T
  26. ): Deferred<T> {
  27.     return GlobalScope.async(context, start, block)
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top