MoETask

class MoETask<T>

Represents an SDK Task. Customers attach onSuccess / onFailure / onComplete to receive the result; the return value is discardable.

onSuccess / onFailure / onComplete callbacks always fire on the main thread.

Cancel: cancel clears registered handlers; the underlying SDK operation is NOT aborted.

Author

Gowtham KK

Since

10.0.0

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
fun cancel()

Clears all attached handlers. Pending callbacks will not fire even if the underlying operation later completes. The operation itself is not interrupted.

Link copied to clipboard
@RestrictTo(value = [RestrictTo.Scope.LIBRARY_GROUP])
fun catching(block: () -> T): MoETask<T>

For SDK internal use only — runs block, resolving with its return value or rejecting with the thrown exception.

Link copied to clipboard
fun onComplete(@MainThread callback: (MoEResult<T>) -> Unit): MoETask<T>

Attaches a callback invoked on the main thread when the operation completes, whether successful or not. Use a when expression on the sealed MoEResult to distinguish.

Link copied to clipboard
fun onFailure(@MainThread callback: (MoERequestFailure) -> Unit): MoETask<T>

Attaches a callback invoked on the main thread when the operation fails.

Link copied to clipboard
fun onSuccess(@MainThread callback: (T) -> Unit): MoETask<T>

Attaches a callback invoked on the main thread when the operation succeeds.

Link copied to clipboard
@RestrictTo(value = [RestrictTo.Scope.LIBRARY_GROUP])
fun reject(error: MoERequestFailure)

For SDK internal use only — rejects the task with a failure.

@RestrictTo(value = [RestrictTo.Scope.LIBRARY_GROUP])
fun reject(throwable: Throwable)

For SDK internal use only — rejects the task wrapping throwable as an unknown error.

Link copied to clipboard
fun MoETask<*>.rejectOnSubmissionFailure(failure: JobSubmissionFailure)

Rejects this MoETask mapping a platform JobSubmissionFailure to the corresponding MoERequestFailureReason. Used when a background job/runnable could not be queued by the com.moengage.platform.internal.thread.executor.TaskHandler.

Link copied to clipboard
@RestrictTo(value = [RestrictTo.Scope.LIBRARY_GROUP])
fun resolve(data: T)

For SDK internal use only — resolves the task with a successful result.