forked from parse-community/Parse-SDK-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from thomax-it/non-recursive-pinning
Non recursive pinning
- Loading branch information
Showing
10 changed files
with
210 additions
and
38 deletions.
There are no files selected for viewing
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
36 changes: 0 additions & 36 deletions
36
coroutines/src/main/java/com/parse/coroutines/ParseQueryCoroutinesExtensions.kt
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...outines/ParseCloudCoroutinesExtensions.kt → ...unction/ParseCloudCoroutinesExtensions.kt
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
8 changes: 8 additions & 0 deletions
8
coroutines/src/main/java/com/parse/coroutines/read/ParseQueryOperation.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.parse.coroutines.read | ||
|
||
interface ParseQueryOperation<out T> { | ||
suspend fun find(): List<T> | ||
suspend fun get(id: String): T | ||
suspend fun first(): T | ||
suspend fun count(): Int | ||
} |
19 changes: 19 additions & 0 deletions
19
coroutines/src/main/java/com/parse/coroutines/read/ParseQueryOperationImpl.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.parse.coroutines.read | ||
|
||
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> { | ||
|
||
override suspend fun find(): List<T> = query.findInternal() | ||
|
||
override suspend fun get(id: String): T = query.getInternal(id) | ||
|
||
override suspend fun first(): T = query.firstInternal() | ||
|
||
override suspend fun count(): Int = query.countInternal() | ||
} |
39 changes: 39 additions & 0 deletions
39
...s/src/main/java/com/parse/coroutines/read/parse_object/ParseObjectCoroutinesExtensions.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
@file:JvmName("ParseObjectCoroutinesExtensions") | ||
@file:Suppress("EXTENSION_SHADOWED_BY_MEMBER") | ||
|
||
package com.parse.coroutines.read.parse_object | ||
|
||
import com.parse.ParseObject | ||
import kotlin.coroutines.resume | ||
import kotlin.coroutines.resumeWithException | ||
import kotlin.coroutines.suspendCoroutine | ||
|
||
suspend fun <T : ParseObject> ParseObject.fetch(): T { | ||
return suspendCoroutine { continuation -> | ||
|
||
fetchInBackground<T> { obj, e -> | ||
if (e == null) continuation.resume(obj) | ||
else continuation.resumeWithException(e) | ||
} | ||
} | ||
} | ||
|
||
suspend fun <T : ParseObject> ParseObject.fetchIfNeeded(): T { | ||
return suspendCoroutine { continuation -> | ||
|
||
fetchIfNeededInBackground<T> { obj, e -> | ||
if (e == null) continuation.resume(obj) | ||
else continuation.resumeWithException(e) | ||
} | ||
} | ||
} | ||
|
||
suspend fun <T : ParseObject> ParseObject.fetchFromLocal(): T { | ||
return suspendCoroutine { continuation -> | ||
|
||
fetchFromLocalDatastoreInBackground<T> { obj, e -> | ||
if (e == null) continuation.resume(obj) | ||
else continuation.resumeWithException(e) | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
coroutines/src/main/java/com/parse/coroutines/read/query/ParseQueryCoroutinesBuilder.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@file:JvmName("ParseQueryCoroutinesBuilder") | ||
@file:Suppress("EXTENSION_SHADOWED_BY_MEMBER") | ||
|
||
package com.parse.coroutines.read.query | ||
|
||
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 | ||
import kotlin.coroutines.CoroutineContext | ||
import kotlin.coroutines.EmptyCoroutineContext | ||
|
||
fun <T : ParseObject> CoroutineScope.launchQuery( | ||
query: ParseQuery<T>, | ||
context: CoroutineContext = EmptyCoroutineContext, | ||
block: suspend ParseQueryOperation<T>.() -> Unit | ||
) : Job { | ||
return launch(context) { | ||
block.invoke(ParseQueryOperationImpl(query)) | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
coroutines/src/main/java/com/parse/coroutines/read/query/ParseQueryCoroutinesExtensions.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
@file:JvmName("ParseQueryCoroutinesExtensions") | ||
|
||
package com.parse.coroutines.read.query | ||
|
||
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> { | ||
return findInternal() | ||
} | ||
|
||
internal suspend fun <T : ParseObject> ParseQuery<T>.findInternal(): List<T> { | ||
return suspendCancellableCoroutine { continuation -> | ||
continuation.invokeOnCancellation { | ||
cancel() | ||
} | ||
|
||
findInBackground { objects, e -> | ||
if (e == null) continuation.resume(objects) | ||
else continuation.resumeWithException(e) | ||
} | ||
} | ||
} | ||
|
||
suspend fun <T : ParseObject> ParseQuery<T>.get(id: String): T { | ||
return getInternal(id) | ||
} | ||
|
||
internal suspend fun <T : ParseObject> ParseQuery<T>.getInternal(id: String): T { | ||
return suspendCancellableCoroutine { continuation -> | ||
continuation.invokeOnCancellation { | ||
cancel() | ||
} | ||
|
||
getInBackground(id) { obj, e -> | ||
if (e == null) continuation.resume(obj) | ||
else continuation.resumeWithException(e) | ||
} | ||
} | ||
} | ||
|
||
suspend fun <T : ParseObject> ParseQuery<T>.first(): T { | ||
return firstInternal() | ||
} | ||
|
||
internal suspend fun <T : ParseObject> ParseQuery<T>.firstInternal(): T { | ||
return suspendCancellableCoroutine { continuation -> | ||
continuation.invokeOnCancellation { | ||
cancel() | ||
} | ||
|
||
getFirstInBackground { obj, e -> | ||
if (e == null) continuation.resume(obj) | ||
else continuation.resumeWithException(e) | ||
} | ||
} | ||
} | ||
|
||
suspend fun <T : ParseObject> ParseQuery<T>.count(): Int { | ||
return countInternal() | ||
} | ||
|
||
internal suspend fun <T : ParseObject> ParseQuery<T>.countInternal(): Int { | ||
return suspendCancellableCoroutine { continuation -> | ||
continuation.invokeOnCancellation { | ||
cancel() | ||
} | ||
|
||
countInBackground { count, e -> | ||
if (e == null) continuation.resume(count) | ||
else continuation.resumeWithException(e) | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...routines/ParseUserCoroutinesExtensions.kt → ...nes/user/ParseUserCoroutinesExtensions.kt
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
27 changes: 27 additions & 0 deletions
27
...main/java/com/parse/coroutines/write/parse_object/ParseObjectCoroutinesWriteExtensions.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
@file:JvmName("ParseObjectCoroutinesWriteExtensions") | ||
@file:Suppress("EXTENSION_SHADOWED_BY_MEMBER") | ||
|
||
package com.parse.coroutines.write.parse_object | ||
|
||
import com.parse.ParseObject | ||
import kotlin.coroutines.resume | ||
import kotlin.coroutines.resumeWithException | ||
import kotlin.coroutines.suspendCoroutine | ||
|
||
suspend fun ParseObject.save() { | ||
return suspendCoroutine { continuation -> | ||
saveInBackground { | ||
if (it == null) continuation.resume(Unit) | ||
else continuation.resumeWithException(it) | ||
} | ||
} | ||
} | ||
|
||
suspend fun ParseObject.pin() { | ||
return suspendCoroutine { continuation -> | ||
pinInBackground { | ||
if (it == null) continuation.resume(Unit) | ||
else continuation.resumeWithException(it) | ||
} | ||
} | ||
} |