-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to specify default dispatcher for formula.
- Loading branch information
Showing
16 changed files
with
95 additions
and
46 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
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
10 changes: 10 additions & 0 deletions
10
formula/src/main/java/com/instacart/formula/RuntimeConfig.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 |
---|---|---|
@@ -1,8 +1,18 @@ | ||
package com.instacart.formula | ||
|
||
import com.instacart.formula.plugin.Inspector | ||
import com.instacart.formula.plugin.Dispatcher | ||
|
||
/** | ||
* @param defaultDispatcher Dispatcher used for event processing (this can be overwritten by | ||
* individual events). By default, formula runs on the thread on which the event arrived on. | ||
* @param inspector Inspector that will be used when configuring the formula. | ||
* @param isValidationEnabled A boolean that validates inputs and outputs by | ||
* running [Formula.evaluate] twice. Should NOT be used in production builds, | ||
* preferably only unit tests. | ||
*/ | ||
class RuntimeConfig( | ||
val defaultDispatcher: Dispatcher? = null, | ||
val inspector: Inspector? = null, | ||
val isValidationEnabled: Boolean = false, | ||
) |
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
27 changes: 26 additions & 1 deletion
27
formula/src/main/java/com/instacart/formula/plugin/Dispatcher.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 |
---|---|---|
@@ -1,14 +1,39 @@ | ||
package com.instacart.formula.plugin | ||
|
||
import com.instacart.formula.FormulaPlugins | ||
|
||
/** | ||
* Dispatches executables to a specific thread. | ||
*/ | ||
interface Dispatcher { | ||
object NoOp : Dispatcher { | ||
object None : Dispatcher { | ||
override fun dispatch(executable: () -> Unit) { | ||
executable() | ||
} | ||
} | ||
|
||
/** | ||
* Uses [Plugin.mainThreadDispatcher] to dispatch executables. | ||
*/ | ||
object Main : Dispatcher { | ||
override fun dispatch(executable: () -> Unit) { | ||
val delegate = FormulaPlugins.mainThreadDispatcher() | ||
delegate.dispatch(executable) | ||
} | ||
} | ||
|
||
/** | ||
* Uses [Plugin.backgroundThreadDispatcher] to dispatch executables. | ||
*/ | ||
object Background : Dispatcher { | ||
override fun dispatch(executable: () -> Unit) { | ||
val delegate = FormulaPlugins.backgroundThreadDispatcher() | ||
delegate.dispatch(executable) | ||
} | ||
} | ||
|
||
/** | ||
* Dispatches [executable] to a thread specified by the [Dispatcher]. | ||
*/ | ||
fun dispatch(executable: () -> Unit) | ||
} |
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.