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
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) { |
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
suspend fun performNetworkequest(){ | |
val response = getResponse('https://blah.com') //suspension point | |
storeResponseInDatabase(response) //suspension point | |
} |
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
fun foo(continuation: Continuation<Unit>): Any? |
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
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") | |
} |
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
__author__ = 'reche_000' | |
import math | |
class Point: | |
def __init__(self, lat=0.0, long=0.0): | |
self.latitude = lat | |
self.longitude = long |