withPayload

inline fun <T> TaskRequest.withPayload(data: T): TaskRequest

Encodes data as JSON and attaches it as the payload for this TaskRequest.

Usage:

data class SyncData(val userId: String, val forceRefresh: Boolean = false)

kmpWorker.enqueue(
TaskRequest(id = "sync-user", type = TaskType.OneTime)
.withPayload(SyncData(userId = "u-123"))
)

Return

A copy of this TaskRequest with the payload set to the JSON-encoded data.

Parameters

data

The strongly-typed object to serialize as payload.