Skip to content

Commit

Permalink
Rename functions that cause shadow members (#1054)
Browse files Browse the repository at this point in the history
* Rename functions that cause shadow members

* Rename prefix from coroutine to suspend
  • Loading branch information
oliveiradev authored Aug 3, 2020
1 parent 8771da9 commit 797786f
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 35 deletions.
6 changes: 3 additions & 3 deletions coroutines/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ Now we can call a parse query using a synchronous style, this is possible when w

```kotlin
launch { // Coroutine builder
val cat = ParseQuery.getQuery(...).find()
val cat = ParseQuery.getQuery(...).coroutineFind()
// get cats without callback
}
```
We use a coroutine builder because `find()` is a suspend function.
We use a coroutine builder because `coroutineFind()` 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.

Expand Down Expand Up @@ -56,7 +56,7 @@ launch { // Coroutine builder
setPassword("my pass")
setEmail("[email protected]")
}.also {
signUp()
coroutineSignUp()
}
}
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@file:JvmName("ParseCloudCoroutinesExtensions")

package com.parse.coroutines.cloudfunction
package com.parse.coroutines

import com.parse.ParseCloud
import kotlin.coroutines.resume
Expand All @@ -14,4 +14,4 @@ suspend fun <T> callCloudFunction(functionName: String, params: Map<String, Any>
else continuation.resumeWithException(e)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
@file:JvmName("ParseObjectCoroutinesExtensions")
@file:Suppress("EXTENSION_SHADOWED_BY_MEMBER")

package com.parse.coroutines.read.parse_object
package com.parse.coroutines

import com.parse.ParseObject
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine

suspend fun <T : ParseObject> ParseObject.fetch(): T {
suspend fun <T : ParseObject> ParseObject.suspendFetch(): T {
return suspendCoroutine { continuation ->

fetchInBackground<T> { obj, e ->
Expand All @@ -18,7 +17,7 @@ suspend fun <T : ParseObject> ParseObject.fetch(): T {
}
}

suspend fun <T : ParseObject> ParseObject.fetchIfNeeded(): T {
suspend fun <T : ParseObject> ParseObject.suspendFetchIfNeeded(): T {
return suspendCoroutine { continuation ->

fetchIfNeededInBackground<T> { obj, e ->
Expand All @@ -36,4 +35,4 @@ suspend fun <T : ParseObject> ParseObject.fetchFromLocal(): T {
else continuation.resumeWithException(e)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
@file:JvmName("ParseObjectCoroutinesWriteExtensions")
@file:Suppress("EXTENSION_SHADOWED_BY_MEMBER")

package com.parse.coroutines.write.parse_object
package com.parse.coroutines

import com.parse.ParseObject
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine

suspend fun ParseObject.save() {
suspend fun ParseObject.suspendSave() {
return suspendCoroutine { continuation ->
saveInBackground {
if (it == null) continuation.resume(Unit)
Expand All @@ -17,11 +16,11 @@ suspend fun ParseObject.save() {
}
}

suspend fun ParseObject.pin() {
suspend fun ParseObject.suspendPin() {
return suspendCoroutine { continuation ->
pinInBackground {
if (it == null) continuation.resume(Unit)
else continuation.resumeWithException(it)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
@file:JvmName("ParseQueryCoroutinesBuilder")
@file:Suppress("EXTENSION_SHADOWED_BY_MEMBER")

package com.parse.coroutines.read.query
package com.parse.coroutines

import com.parse.ParseObject
import com.parse.ParseQuery
import com.parse.coroutines.read.ParseQueryOperation
import com.parse.coroutines.read.ParseQueryOperationImpl
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
Expand All @@ -21,4 +18,4 @@ fun <T : ParseObject> CoroutineScope.launchQuery(
return launch(context) {
block.invoke(ParseQueryOperationImpl(query))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
@file:JvmName("ParseQueryCoroutinesExtensions")

package com.parse.coroutines.read.query
package com.parse.coroutines

import com.parse.ParseObject
import com.parse.ParseQuery
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException

suspend fun <T : ParseObject> ParseQuery<T>.find(): List<T> {
suspend fun <T : ParseObject> ParseQuery<T>.suspendFind(): List<T> {
return findInternal()
}

Expand All @@ -25,7 +25,7 @@ internal suspend fun <T : ParseObject> ParseQuery<T>.findInternal(): List<T> {
}
}

suspend fun <T : ParseObject> ParseQuery<T>.get(id: String): T {
suspend fun <T : ParseObject> ParseQuery<T>.getById(id: String): T {
return getInternal(id)
}

Expand Down Expand Up @@ -59,7 +59,7 @@ internal suspend fun <T : ParseObject> ParseQuery<T>.firstInternal(): T {
}
}

suspend fun <T : ParseObject> ParseQuery<T>.count(): Int {
suspend fun <T : ParseObject> ParseQuery<T>.suspendCount(): Int {
return countInternal()
}

Expand All @@ -74,4 +74,4 @@ internal suspend fun <T : ParseObject> ParseQuery<T>.countInternal(): Int {
else continuation.resumeWithException(e)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.parse.coroutines.read
package com.parse.coroutines

interface ParseQueryOperation<out T> {
suspend fun find(): List<T>
suspend fun get(id: String): T
suspend fun first(): T
suspend fun count(): Int
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.parse.coroutines.read
package com.parse.coroutines

import com.parse.ParseObject
import com.parse.ParseQuery
import com.parse.coroutines.read.query.countInternal
import com.parse.coroutines.read.query.findInternal
import com.parse.coroutines.read.query.firstInternal
import com.parse.coroutines.read.query.getInternal

class ParseQueryOperationImpl<T : ParseObject>(private val query: ParseQuery<T>) : ParseQueryOperation<T> {

Expand All @@ -16,4 +12,4 @@ class ParseQueryOperationImpl<T : ParseObject>(private val query: ParseQuery<T>)
override suspend fun first(): T = query.firstInternal()

override suspend fun count(): Int = query.countInternal()
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@file:JvmName("ParseUserCoroutinesExtensions")

package com.parse.coroutines.user
package com.parse.coroutines

import com.parse.ParseUser
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine

suspend fun ParseUser.signUp(): ParseUser {
suspend fun ParseUser.suspendSignUp(): ParseUser {
return suspendCoroutine { continuation ->
signUpInBackground { e ->
if (e == null) continuation.resume(this)
Expand Down

0 comments on commit 797786f

Please sign in to comment.