-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31df4fc
commit a795319
Showing
12 changed files
with
97 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
rm -rf "../ios/ios-frameworks/run_blocking.framework/" | ||
rm -rf "../ios/ios-frameworks/run_blocking.framework.dSYM" | ||
|
||
cp -R "./build/bin/ios/main/debug/framework/run_blocking.framework" "../ios/ios-frameworks/run_blocking.framework/" | ||
|
||
cp -R "./build/bin/ios/main/debug/framework/run_blocking.framework.dSYM" "../ios/ios-frameworks/run_blocking.framework.dSYM/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package example | ||
|
||
import io.ktor.client.HttpClient | ||
import io.ktor.client.call.call | ||
import io.ktor.client.response.readText | ||
import kotlinx.io.core.use | ||
|
||
expect fun <T> runBlocking(block: suspend () -> T): T | ||
|
||
fun healthCheck(): String { | ||
return runBlocking { | ||
HttpClient().use { | ||
it.call("http:https://this.is.a.test.instructure.com/health_check").response.readText() | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package example | ||
|
||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class CommonTest { | ||
|
||
@Test | ||
fun testHealthCheck() { | ||
assertEquals("canvas ok", healthCheck()) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package example | ||
|
||
import platform.Foundation.NSDate | ||
import platform.Foundation.NSRunLoop | ||
import platform.Foundation.addTimeInterval | ||
import platform.Foundation.runUntilDate | ||
|
||
class Expectation<T> { | ||
private var waiting = true | ||
private var result: T? = null | ||
|
||
fun fulfill(result: T?) { | ||
waiting = false | ||
this.result = result | ||
} | ||
|
||
fun wait(): T? { | ||
while (waiting) { | ||
advanceRunLoop() | ||
} | ||
|
||
return result | ||
} | ||
} | ||
|
||
private fun advanceRunLoop() { | ||
val date = NSDate().addTimeInterval(1.0) as NSDate | ||
NSRunLoop.mainRunLoop.runUntilDate(date) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package example | ||
|
||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.GlobalScope | ||
import kotlinx.coroutines.Runnable | ||
import kotlinx.coroutines.launch | ||
import platform.Foundation.NSRunLoop | ||
import platform.Foundation.performBlock | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
actual fun <T> runBlocking(block: suspend () -> T): T { | ||
val expectation = Expectation<T>() | ||
|
||
GlobalScope.launch(MainRunLoopDispatcher) { | ||
expectation.fulfill(block.invoke()) | ||
} | ||
|
||
return expectation.wait() ?: throw RuntimeException("runBlocking failed") | ||
} | ||
|
||
private object MainRunLoopDispatcher : CoroutineDispatcher() { | ||
override fun dispatch(context: CoroutineContext, block: Runnable) { | ||
NSRunLoop.mainRunLoop().performBlock { | ||
block.run() | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package example | ||
|
||
import kotlinx.coroutines.runBlocking | ||
|
||
actual fun <T> runBlocking(block: suspend () -> T): T = runBlocking { block.invoke() } |
This file was deleted.
Oops, something went wrong.