707
// Returns the workflow component (which is *chasmworkflow.Workflow) and the CHASM mutable context.
708
// This method is for write operations. Callers can type assert to *chasmworkflow.Workflow if needed.
709
>
func (ms *MutableStateImpl) ChasmWorkflowComponent(ctx context.Context) (*chasmworkflow.Workflow, chasm.MutableContext, error) {
mutable_state_impl.go
710
>
chasmCtx := chasm.NewMutableContext(ctx, ms.chasmTree.(*chasm.Node))
711
>
rootComponent, err := ms.chasmTree.ComponentByPath(chasmCtx, nil)
712
>
if err != nil {
713
return nil, nil, err
714
}
716
>
if !ok {
717
return nil, nil, serviceerror.NewInternalf("expected workflow component, but got %T", rootComponent)
718
}
720
}
721
722
>
func (ms *MutableStateImpl) EnsureChasmWorkflowComponent(ctx context.Context) {
mutable_state_impl.go
723
>
// Initialize chasm tree once for new workflows.
724
>
// Using context.Background() because this is done outside an actual request context and the
725
>
// chasmworkflow.NewWorkflow does not actually use it currently.
726
>
root, ok := ms.chasmTree.(*chasm.Node)
727
>
softassert.That(ms.logger, ok, "chasmTree cast failed")
728
>
729
>
if root.ArchetypeID() == chasm.UnspecifiedArchetypeID {
730
mutableContext := chasm.NewMutableContext(ctx, root)
731
if err := root.SetRootComponent(chasmworkflow.NewWorkflow(mutableContext, chasm.NewMSPointer(ms))); err != nil {