{"id":27598500,"url":"https://github.com/bjoernq/whitemagic","last_synced_at":"2026-04-20T13:38:15.671Z","repository":{"id":84535379,"uuid":"121107839","full_name":"bjoernQ/whitemagic","owner":"bjoernQ","description":"An easy way to do lifecycle aware async task style thing on Android with Kotlin","archived":false,"fork":false,"pushed_at":"2018-10-22T17:14:55.000Z","size":150,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-14T14:45:01.570Z","etag":null,"topics":["android","coroutines"],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bjoernQ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-02-11T09:35:10.000Z","updated_at":"2018-10-22T17:14:03.000Z","dependencies_parsed_at":"2024-04-28T13:30:45.814Z","dependency_job_id":null,"html_url":"https://github.com/bjoernQ/whitemagic","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/bjoernQ/whitemagic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjoernQ%2Fwhitemagic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjoernQ%2Fwhitemagic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjoernQ%2Fwhitemagic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjoernQ%2Fwhitemagic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bjoernQ","download_url":"https://codeload.github.com/bjoernQ/whitemagic/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjoernQ%2Fwhitemagic/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32049274,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T11:35:06.609Z","status":"ssl_error","status_checked_at":"2026-04-20T11:34:48.899Z","response_time":94,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","coroutines"],"created_at":"2025-04-22T14:14:41.830Z","updated_at":"2026-04-20T13:38:15.642Z","avatar_url":"https://github.com/bjoernQ.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Whitemagic\n\nAn easy way to do lifecycle aware async task style thing on Android with Kotlin\n\n# About\n\nEver wanted to write code like this?\n```kotlin\nasync {\n    loadingIndicatorShown = true\n    val success = inBackground { Repository.longRunningOperation() }\n    loadingIndicatorShown = false\n    if(!success){\n        showError = true\n    }\n}\n```\n\nNow you can!\n\n# How to\n\nThe library defines a couple of extension functions for LifecycleOwner:\n\nFunction|Description\n--------|-----------\nasync | wrap your async code inside the async lambda - it's important to not reference the outer scope from here. Therefore you get \"target\" to reference it.\ninBackground | inside \"async\" you can use this to execute the given lambda on a background thread, the lambda can return a result\ncall | the lambda needs to return a tag (String) which you can refer to with findCallbackFor to return the actual result any time later\n\nThe best way to learn about the usage might be to look into the sample code - code is worth a thousand words, you know\n\nThere is also a LifecycleAwareAndroidViewModel which extends AndroidViewModel but a Lifecycle can be attached.\n\nIt's easy to use this library with it and also LiveData is easy to use.\n\nTo make use of LifecycleAwareAndroidViewModel you need to attach an actual Lifecycle\n\n```kotlin\nvm.attach(this)\n```\n\nActual code in the ViewModel could look like this (code from the weirdo sample app :) )\n```kotlin\nasync\u003cMainViewModel\u003e {\n            // we certainly don't need the permission but just for demonstration we request it\n            val locationPermissionGranted = call\u003cBoolean\u003e { requestPermission(target.actionCallbacks.getActivity(), Manifest.permission.ACCESS_FINE_LOCATION, \"We need Location Permission\", \"Not really but this is a sample app.\") }\n\n            Toast.makeText(target.getApplication\u003cApp\u003e(), \"Value is $locationPermissionGranted\", Toast.LENGTH_SHORT).show()\n\n            if (locationPermissionGranted) {\n                val websiteUrl = call\u003cString\u003e { target.actionCallbacks.showInputDialog() }\n\n                val shouldAddToList = call\u003cBoolean\u003e { target.actionCallbacks.showWebsiteStats(websiteUrl) }\n\n                if (shouldAddToList) {\n                    inBackground {\n                        App.component().getDatabase().webSiteDao().insert(WebSite(websiteUrl))\n                    }\n                } else {\n                    println(\"Error/Canceled\")\n                }\n            }\n\n        }\n```\n\n# Things missing\n\n- better documentation (obviously)\n- a better sample app (the current is really weird, I know)\n- unit tests at least for the core functionality\n\n# Versioning and how to get it\n\nFor now it's just available via JitPack.\n\nVersions below 1.0.0 are considered \"early access\" and things might change. Starting with 1.0.0 the API should be stable and the versioning scheme will follow the rules of semantic versioning.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjoernq%2Fwhitemagic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbjoernq%2Fwhitemagic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjoernq%2Fwhitemagic/lists"}