Skip to content

Instantly share code, notes, and snippets.

View recheej's full-sized avatar

Rechee recheej

View GitHub Profile
fun performNetworkRequest(cont: Continuation<Unit>): Any? {
val stateMachine = object: ContinuationImpl<Unit> {
var label = 0
override fun resumeWith(...) {
performNetworkRequest(this) // call with this state machine again
}
}
var response: Response? = null
switch(stateMachine.label) {
suspend fun performNetworkequest(){
val response = getResponse('https://blah.com') //suspension point
storeResponseInDatabase(response) //suspension point
}
fun foo(continuation: Continuation<Unit>): Any?
suspend fun foo() {
// let's assume called on main thread
delay(1000) // resume in 1 second
// we resumed after 1 second. which thread? that'll be answered in a future blog
println("foo completed")
}
__author__ = 'reche_000'
import math
class Point:
def __init__(self, lat=0.0, long=0.0):
self.latitude = lat
self.longitude = long