Skip to content

Instantly share code, notes, and snippets.

@kasem-sm
Created May 30, 2022 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasem-sm/98fe841b9ec034d225d129d990aec4ae to your computer and use it in GitHub Desktop.
Save kasem-sm/98fe841b9ec034d225d129d990aec4ae to your computer and use it in GitHub Desktop.
When Jetpack's Glance met his fellow worker, Work Manager
@HiltWorker
internal class DailyReadWorkerTask @AssistedInject constructor(
@Assisted private val context: Context,
@Assisted workParams: WorkerParameters,
private val api: ArticleApiService,
private val cache: ArticleDatabaseService,
) : CoroutineWorker(context, workParams) {
override suspend fun doWork(): Result {
val article = api.getFromUsersSubscription().mapToEntity()
return try {
// Update the widget's text content
Result.success()
} catch(e: Exception) {
Result.retry()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment