Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement