-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/sync initializer bloc lifecycle (#12)
* some refactoring to prepare the actual functionality * re-adding the state machine, not connected to the Bloc lifecycle yet * use AtomicFu in the state machine to synchronize axcess to the state variable * WIP * WIP * fix a compile error * document internal lifecycle as svg * a ton of changes... * re-add the CoroutineRunner to reducers and fix some initializer related lifecycle issues * update the documentation * minor library updates * make test more robust * upload test results * upload test results * upload test results * new version number * upload test results Co-authored-by: Emanuel Moecklin <emanuel.moecklin@gmail.com>
- Loading branch information
Showing
47 changed files
with
1,270 additions
and
364 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
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
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
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
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
31 changes: 31 additions & 0 deletions
31
bloc-core/src/commonMain/kotlin/com/onegravity/bloc/internal/Coroutine.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,31 @@ | ||
package com.onegravity.bloc.internal | ||
|
||
import com.onegravity.bloc.utils.CoroutineRunner | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.SupervisorJob | ||
import kotlinx.coroutines.cancel | ||
|
||
/** | ||
* Helper class to manage CoroutineScope and CoroutineRunner | ||
*/ | ||
internal class Coroutine(private val dispatcher: CoroutineDispatcher) { | ||
internal var scope: CoroutineScope? = null | ||
private set(value) { | ||
if (value != null) { | ||
field = value | ||
runner = CoroutineRunner(value) | ||
} | ||
} | ||
|
||
internal var runner: CoroutineRunner? = null | ||
private set | ||
|
||
internal fun onStart() { | ||
scope = CoroutineScope(SupervisorJob() + dispatcher) | ||
} | ||
|
||
internal fun onStop() { | ||
scope?.cancel() | ||
} | ||
} |
Oops, something went wrong.