-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1842 from Adyen/chore/dispatcher-provider
Introduce DispatcherProvider
- Loading branch information
Showing
20 changed files
with
101 additions
and
50 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
57 changes: 57 additions & 0 deletions
57
checkout-core/src/main/java/com/adyen/checkout/core/DispatcherProvider.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,57 @@ | ||
/* | ||
* Copyright (c) 2024 Adyen N.V. | ||
* | ||
* This file is open source and available under the MIT license. See the LICENSE file for more info. | ||
* | ||
* Created by ozgur on 16/10/2024. | ||
*/ | ||
|
||
package com.adyen.checkout.core | ||
|
||
import androidx.annotation.RestrictTo | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.MainCoroutineDispatcher | ||
|
||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
object DispatcherProvider { | ||
|
||
private var mainFactory = { Dispatchers.Main } | ||
val Main: MainCoroutineDispatcher get() = mainFactory() | ||
|
||
private var defaultFactory = { Dispatchers.Default } | ||
val Default: CoroutineDispatcher get() = defaultFactory() | ||
|
||
private var ioFactory = { Dispatchers.IO } | ||
val IO: CoroutineDispatcher get() = ioFactory() | ||
|
||
fun overrideMain(dispatcher: MainCoroutineDispatcher) { | ||
mainFactory = { dispatcher } | ||
} | ||
|
||
fun overrideIO(dispatcher: CoroutineDispatcher) { | ||
ioFactory = { dispatcher } | ||
} | ||
|
||
fun overrideDefault(dispatcher: CoroutineDispatcher) { | ||
defaultFactory = { dispatcher } | ||
} | ||
|
||
fun resetMain() { | ||
mainFactory = { Dispatchers.Main } | ||
} | ||
|
||
fun resetIO() { | ||
ioFactory = { Dispatchers.IO } | ||
} | ||
|
||
fun resetDefault() { | ||
defaultFactory = { Dispatchers.Default } | ||
} | ||
|
||
fun resetAll() { | ||
resetMain() | ||
resetIO() | ||
resetDefault() | ||
} | ||
} |
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
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
Oops, something went wrong.