Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create an extension on WorkflowHost for running a workflow and just getting its outputs #389

Closed
zach-klippenstein opened this issue Jun 3, 2019 · 3 comments
Assignees
Labels
enhancement New feature or request kotlin Affects the Kotlin library. obsolete Issues that have been closed because they are no longer relevant

Comments

@zach-klippenstein
Copy link
Collaborator

I have seen a few uses of flatMapWorkflow where only the OutputTs are needed. This is easy to pull into an extension on WorkflowHost that doesn't have all the same problems as flatMapWorkflow (see #377).

@zach-klippenstein zach-klippenstein added the enhancement New feature or request label Jun 3, 2019
@zach-klippenstein zach-klippenstein added this to the kotlin v0.18.0 milestone Jun 3, 2019
@zach-klippenstein zach-klippenstein self-assigned this Jun 3, 2019
@zach-klippenstein
Copy link
Collaborator Author

zach-klippenstein commented Jun 3, 2019

Prototyping internally first, to make sure it solves the right problems.

API looks like:

/**
 * Returns a [ConnectableFlowable] that, when connected, will subscribe to [inputs], starts [workflow],
 * and emits all outputs emitted by the workflow. Renderings and snapshots are dropped. The workflow
 * will not start until [inputs] emits its first value.
 *
 * Outputs will be multicasted to all subscribers (i.e. the returned [Flowable] is
 * [published][Flowable.publish].
 *
 * The workflow will be executed on the dispatcher configured on this [WorkflowHost.Factory].
 *
 * @param snapshot If non-null, used to restore [workflow].
 * @return A [ConnectableFlowable] that will multicast to all subscribers (i.e. is
 * [published][Flowable.publish]) when connected. Nothing will be emitted until connection. Disposing
 * the connection and re-connecting will discard any state and restart the workflow runtime, again
 * restoring from [snapshot] if non-null.
 */
fun <InputT, OutputT : Any> WorkflowHost.Factory.runOutputs(
  workflow: Workflow<InputT, OutputT, *>,
  inputs: Flowable<out InputT>,
  snapshot: Snapshot? = null
): ConnectableFlowable<out OutputT> = TODO()

Returns a disconnected ConnectableFlowable to force multicasting (whenever I've seen code that calls ReceiveChannel.asObservable, I and everyone else forgets to multicast it) but still allow the caller to control the upstream subscription. Callers are expected to be managing their own lifetime and thus be able to own the connection.

cc @rjrjr @davidapgar @timdonnelly

@zach-klippenstein
Copy link
Collaborator Author

This will depend on converting WorkflowHost to be two-output. I can do this with channels now, or just use Flow once #409 lands. I'm tempted to do the latter, since both are experimental anyway and Flow is really the best way to express this API.

@zach-klippenstein zach-klippenstein added the obsolete Issues that have been closed because they are no longer relevant label Jul 10, 2019
@zach-klippenstein
Copy link
Collaborator Author

I don't have a use case for this that isn't easy to do with the new launchWorkflowIn API. Closing.

@zach-klippenstein zach-klippenstein added the kotlin Affects the Kotlin library. label Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request kotlin Affects the Kotlin library. obsolete Issues that have been closed because they are no longer relevant
Projects
None yet
Development

No branches or pull requests

1 participant