Skip to content

Instantly share code, notes, and snippets.

View KhomDrake's full-sized avatar

Vinicius Viana KhomDrake

View GitHub Profile
mathScope.launch(Job()) {
}
val mathScope = CoroutineScope(Job() + Dispatchers.IO)
mathScope.launch {
if(mathScope.ensureActive()) { // ensures that the scope is active and if not, it will throw a exception.
// continue the calculation
}
if(mathScope.isActive) { // returns true or false if the scope is active or not
// continue the calculation
}
}
mathScope.cancel()
mathScope.launch {
// calculate PI
}
suspend fun makeLogin(login: String, password: String) : Token {
// request login
return token
}
suspend fun loadMovies(token: Token) : List<Movie> {
val token = makeLogin("someValue", "someValue")
// request movies with token
return movies
}
suspend fun makeLogin(login: String, password: String, callback: (Token) -> Unit) {
// request login
callback(token)
}
suspend fun loadMovies(callback: (List<Movie>) -> Unit) {
makeLogin("someValue", "someValue") { token ->
// request movies with token
callback(movies)
}
suspend fun makeLogin(login: String, password: String, callback: (Token) -> Unit) {
// request login
callback(token)
}
suspend fun loadMovies(callback: (List<Movie>) -> Unit) {
makeLogin("someValue", "someValue") { token ->
// request movies with token
callback(movies)
}
fun makeLogin(login: String, password: String, callback: (Token) -> Unit) {
// request login
callback(token)
}
fun loadMovies(callback: (List<Movie>) -> Unit) {
makeLogin("someValue", "someValue") { token ->
// request movies with token
callback(movies)
}
suspend fun makeSomething() {
// do some stuff
}