Kotlin coroutines support for Parse Android
After including JitPack:
dependencies {
implementation "com.github.parse-community.Parse-SDK-Android:coroutines:latest.version.here"
}
Now we can call a parse query using a synchronous style, this is possible when we use coroutines. We need to use a regular coroutine builder:
launch { // Coroutine builder
val cat = ParseQuery.getQuery(...).find()
// get cats without callback
}
We use a coroutine builder because find()
is a suspend function.
We can also, use a function like a coroutine builder, it will be provider us a flexibility call our query without any extensions function.
launchQuery(query) {
// doing operations like find, get, first and count
}
It uses a a regular coroutine builder launch
and pass as receiver a `ParseQueryOperation``
We can call cloud function inline:
launch { // Coroutine builder
val catThumb = callCloudFunction("getThumbnail", mapOf("url" to "https://cat.jpg"))
// get cats without callback
}
SignUp:
launch { // Coroutine builder
user = ParseUser().apply {
setUsername("my name")
setPassword("my pass")
setEmail("[email protected]")
}.also {
signUp()
}
}
Login:
launch { // Coroutine builder
val user = parseLogIn("username", "password")
}
We can save, pinning and fetch parse objects use coroutines as well.
When contributing to the coroutines
module, please first consider if the extension function you are wanting to add would potentially be better suited in the main parse
module. If it is something specific to Kotlin users or only useful in a Kotlin project, feel free to make a PR adding it to this module. Otherwise, consider adding the addition to the parse
module itself, so that it is still usable in Java.
Copyright (c) 2015-present, Parse, LLC.
All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree. An additional grant
of patent rights can be found in the PATENTS file in the same directory.