danielgerlag / workflow-core

Lightweight workflow engine for .NET Standard
MIT License
5.4k stars 1.2k forks source link

CompensateWithSequence does not execute sequencially with CompensateWith steps. #1205

Open andrei-micuda opened 1 year ago

andrei-micuda commented 1 year ago

Describe the bug Having a CompensateWithSequence step causes the compensation to happen in parallel with CompensateWith steps.

To Reproduce Steps to reproduce the behavior:

builder.Saga(x => x
    .StartWith(_ => Console.WriteLine("Step1."))
        .CompensateWith(_ => Console.WriteLine("Compensating Step1."))
    .Then(_ => Console.WriteLine("Step2."))
        .CompensateWithSequence(seq => seq
            .StartWith(_ => Console.WriteLine("Compensating Step2."))
            .Then(_ => Thread.Sleep(3000))
            .Then(_ => Console.WriteLine("Finished compensating Step2."))
        )
    .Then(_ => throw new Exception()));

The output of the workflow is:

Step1.
Step2.
Compensating Step1.
Compensating Step2.
Finished compensating Step2.

Expected behavior The expected output of the workflow is:

Step1.
Step2.
Compensating Step2.
Finished compensating Step2.
Compensating Step1.