#Can anyone explain to me why this machine don't trigger my parallel state ?

1 messages · Page 1 of 1 (latest)

tame pine
#
import { createMachine } from "xstate";

export const machine = createMachine(
  {
    id: "Analysis",
    initial: "Idle",
    states: {
      Idle: {
        on: {
          "candle.process": {target: "Processing Indicators"},
        },
      },
      "Processing Indicators": {
        states: {
          "Bollinger Bands Processing": {
            on: {
              "bb.calculated": {target: "Volatility Cycle Calculation"},
            },
          },
          "Volatility Cycle Calculation": {
            on: {
              "vc.calculated": {target: "Phase Calculation"},
            },
          },
          "Phase Calculation": {
            on: {
              "bb.phase.calculated": {
                target: "Bollinger Bands Processed",
              },
            },
          },
          "Bollinger Bands Processed": {
            type: "final",
          },
          "Volume Moving Average Calculation": {
            on: {
              "vma.calculated": {
                target: "VMA Calculated",
              },
            },
          },
          "Zig Zag Calculation": {
            on: {
              "zigzag.calculated": {
                target: "Zig Zag Processed",
              },
            },
          },
          "VMA Calculated": {
            type: "final",
          },
          "Zig Zag Processed": {
            type: "final",
          },
        },
        type: "parallel",
        onDone: {
          target: "Compression Finder",
        },
      },
      "Compression Finder": {
        on: {
          "Event 1": {
            target: "Idle",
          },
        },
      },
    },
    types: {
      events: {} as
        | { type: "" }
        | { type: "Event 1" }
        | { type: "candle.process" }
        | { type: "bb.calculated" }
        | { type: "vc.calculated" }
        | { type: "bb.phase.calculated" }
        | { type: "vma.calculated" }
        | { type: "zigzag.calculated" },
    },
  },
);
rose sapphire
#

Because every region is entered simultaneously and every state you have defined is already in its final state

#

The dashed boxes are the states entered in a parallel state

#

Looks like you want 3 child states instead

tame pine
#

I want 3 child states indeed, but I want them to run concurently

#

is it possible ??

#

I thought it was the goal of the parallel state

rose sapphire
#

All the states you've defined are at the same level hierachically

tame pine
#

Ok, how can I have 3 "child" workflow in my parent state "Processing Indicators" then ?

#

I'm really struggling with this error 😅

rose sapphire
#
export const machine = createMachine(
  {
    id: "Analysis",
    initial: "Idle",
    states: {
      Idle: {
        on: {
          "candle.process": {
            target: "Processing Indicators",
          },
        },
      },
      "Processing Indicators": {
        states: {
          Bollinger: {
            initial: "Bollinger Bands Processing",
            states: {
              "Bollinger Bands Processing": {
                on: {
                  "bb.calculated": {
                    target: "Volatility Cycle Calculation",
                  },
                },
              },
              "Volatility Cycle Calculation": {
                on: {
                  "vc.calculated": {
                    target: "Phase Calculation",
                  },
                },
              },
              "Phase Calculation": {
                on: {
                  "bb.phase.calculated": {
                    target: "Bollinger Bands Processed",
                  },
                },
              },
              "Bollinger Bands Processed": {
                type: "final",
              },
            },
          },
          Volume: {
            initial: "Volume Moving Average Calculation",
            states: {
              "Volume Moving Average Calculation": {
                on: {
                  "vma.calculated": {
                    target: "VMA Calculated",
                  },
                },
              },
              "VMA Calculated": {
                type: "final",
              },
            },
          },
          "Zig Zag": {
            initial: "Zig Zag Calculation",
            states: {
              "Zig Zag Calculation": {
                on: {
                  "zigzag.calculated": {
                    target: "Zig Zag Processed",
                  },
                },
              },
              "Zig Zag Processed": {
                type: "final",
              },
            },
          },
        },
        type: "parallel",
        onDone: {
          target: "Compression Finder",
        },
      },
      "Compression Finder": {
        on: {
          "Event 1": {
            target: "Idle",
          },
        },
      },
    },
    types: {
      events: {} as
        | { type: "candle.process" }
        | { type: "Event 1" }
        | { type: "bb.calculated" }
        | { type: "vc.calculated" }
        | { type: "bb.phase.calculated" }
        | { type: "zigzag.calculated" }
        | { type: "vma.calculated" },
    },
  },
  {
    actions: {},
    actors: {},
    guards: {},
    delays: {},
  },
);

tame pine
#

Ooooh indeed

#

seems pretty obvious 😅

#

thx for your help, it's time for me to go to sleep if I'm stuck on that type of error 🤣

rose sapphire
#

It was a welcome distraction from figuring out how to use the Rust borrow checker across threads, sleep is a great idea instead of going back to that!

tame pine
#

good luck with the borrow checker 😉

rose sapphire
#

tomorrow me's problem, I'm following your lead