|
| 1 | +# Parse SDK Android Coroutines |
| 2 | +Kotlin coroutines support for Parse Android |
| 3 | + |
| 4 | +## Setup |
| 5 | + |
| 6 | +### Installation |
| 7 | +After including JitPack: |
| 8 | + |
| 9 | +```groovy |
| 10 | +dependencies { |
| 11 | + implementation "com.github.parse-community.Parse-SDK-Android:coroutines:latest.version.here" |
| 12 | +} |
| 13 | +``` |
| 14 | + |
| 15 | +## Use Parse Coroutines |
| 16 | + |
| 17 | +### ParseQuery |
| 18 | + |
| 19 | +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: |
| 20 | + |
| 21 | +```kotlin |
| 22 | +launch { // Coroutine builder |
| 23 | + val cat = ParseQuery.getQuery(...).find() |
| 24 | + // get cats without callback |
| 25 | +} |
| 26 | +``` |
| 27 | +We use a coroutine builder because `find()` is a suspend function. |
| 28 | + |
| 29 | +### ParseCloud |
| 30 | + |
| 31 | +We can call cloud function inline: |
| 32 | + |
| 33 | + ```kotlin |
| 34 | +launch { // Coroutine builder |
| 35 | + val catThumb = callCloudFunction("getThumbnail", mapOf("url" to "https://cat.jpg")) |
| 36 | + // get cats without callback |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +### ParseUser |
| 41 | + |
| 42 | +SignUp: |
| 43 | + |
| 44 | +```kotlin |
| 45 | +launch { // Coroutine builder |
| 46 | + user = ParseUser().apply { |
| 47 | + setUsername("my name") |
| 48 | + setPassword("my pass") |
| 49 | + |
| 50 | + }.also { |
| 51 | + signUp() |
| 52 | + } |
| 53 | +} |
| 54 | +``` |
| 55 | +Login: |
| 56 | + |
| 57 | +```kotlin |
| 58 | +launch { // Coroutine builder |
| 59 | + val user = parseLogIn("username", "password") |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +## Contributing |
| 64 | +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. |
| 65 | + |
| 66 | +## License |
| 67 | + Copyright (c) 2015-present, Parse, LLC. |
| 68 | + All rights reserved. |
| 69 | + |
| 70 | + This source code is licensed under the BSD-style license found in the |
| 71 | + LICENSE file in the root directory of this source tree. An additional grant |
| 72 | + of patent rights can be found in the PATENTS file in the same directory. |
0 commit comments