You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Description
As stated in issue #680, the current eventLoop method handling for sequenceMsg executes only once nested BatchMsg in the proper order, but nested sequenceMsg and multiple nested BatchMsg or sequenceMsg will not follow the specified order.
This is due to the fact that the eventLoop method calls p.Send without checking the result of the message that is the result of the call to the command contained in sequenceMsg all the way through the nest.
Example
The following shows the desired and actual calling order for a given sequenceMsg.
Command1 is generated by tea.Batch, so Command1-1 and Command1-2 are executed in parallel.
Command1-1 is generated by tea.Sequence, so Command1-1-1 and Command1-1-2 are executed in sequence.
Command1-2 is generated by tea.Batch, so Command1-2-1 and Command1-2-2 are executed in parallel.
Command2 is executed after all commands executed by Command1 (1-1-1, 1-1-2, 1-2-1, 1-2-2) have been executed.
Command3 is executed after Command2 finishes.
Command3 is generated by tea.Sequence, so Command3-1 and Command3-2 are executed in sequence.
Command3-1 is generated by tea.Batch, so Command3-1-1 and Command3-1-2 are executed simultaneously.
Command3-2 is generated by tea.Sequence, so Command3-2-1 and Command3-2-2 are executed in sequence.
Quit is executed after all these commands are completed.
This is a simple sequence diagram for Command1.
In the figure below, the solid black line represents the go routine, the solid red line represents the invocation of the go routine, and the dashed red line represents the end of the go routine being notified to the go routine that invoked the go routine just finished.
This is a simple sequence diagram for Command3.
In the current implementation, the above commands are executed as shown below.
In this section of tea.go, the bubble tea works like sequence diagram above.
The reason processing is not executed in the specified order is that eventloop is asked to execute all cmd()'s results asynchronously using p.Send() without checking whether they are sequenceMsg or BatchMsg or other Messages.
The problem and its cause when Cmd3 is executed with the current implementation is discussed in #680 and #843. Briefly, when sequenceMsg is nested in sequenceMsg, the inner sequenceMsg is sent to eventloop with p.Send, so it cannot maintain proper order with the outer sequenceMsg.
Describe the solution you'd like
improve implementation of #843. To execute the command as specified for a sequenceMsg or BatchMsg of any depth of nesting, the command should be executed using a recursive function.
Describe alternatives you've considered
Since the current implementation supports nesting by directly examining the result of the command invocation and nesting if statements instead of using a recursive function, the if statements must also be nested by the corresponding depth of nesting.
For now, I have not come up with an alternative.
Additional context
breaking change
Consideration should be given so that this change is not breaking. This modification changes the order in which the Command is invoked. However, in the current implementation, Command was simply executed asynchronously with p.Send without adhering to the order specified by tea.Sequence or tea.Batch. Therefore, the commands in the program that work correctly at this time are not guaranteed to be in sequence. In other words, the program works even if the order is not guaranteed. Therefore, even if this modification guarantees order, it is unlikely that a program that was already working will stop working. On the other hand, the programs that will not work correctly due to this modification are programs with bugs that happen to be working well due to the unguaranteed execution order by p.Send and eventloop.
$ go run main.go
1-1-1 // after 1000ms
1-2-2 // after 1250ms
1-2-1 // after 1500ms
1-1-2 // after 2000ms
2
3-1-1 // after 2500ms
3-1-2 // after 3000ms
3-2-1 // after 3750ms
3-2-2 // after 4250ms
Is your feature request related to a problem? Please describe.
Description
As stated in issue #680, the current
eventLoop
method handling forsequenceMsg
executes only once nestedBatchMsg
in the proper order, but nestedsequenceMsg
and multiple nestedBatchMsg
orsequenceMsg
will not follow the specified order.This is due to the fact that the
eventLoop
method callsp.Send
without checking the result of the message that is the result of the call to the command contained insequenceMsg
all the way through the nest.Example
The following shows the desired and actual calling order for a given
sequenceMsg
.These are important points of the example above.
tea.Batch
, so Command1-1 and Command1-2 are executed in parallel.tea.Sequence
, so Command1-1-1 and Command1-1-2 are executed in sequence.tea.Batch
, so Command1-2-1 and Command1-2-2 are executed in parallel.tea.Sequence
, so Command3-1 and Command3-2 are executed in sequence.tea.Batch
, so Command3-1-1 and Command3-1-2 are executed simultaneously.tea.Sequence
, so Command3-2-1 and Command3-2-2 are executed in sequence.This is a simple sequence diagram for Command1.
In the figure below, the solid black line represents the go routine, the solid red line represents the invocation of the go routine, and the dashed red line represents the end of the go routine being notified to the go routine that invoked the go routine just finished.
This is a simple sequence diagram for Command3.
In the current implementation, the above commands are executed as shown below.
In this section of tea.go, the bubble tea works like sequence diagram above.
The reason processing is not executed in the specified order is that
eventloop
is asked to execute allcmd()
's results asynchronously usingp.Send()
without checking whether they aresequenceMsg
orBatchMsg
or other Messages.The problem and its cause when Cmd3 is executed with the current implementation is discussed in #680 and #843. Briefly, when
sequenceMsg
is nested insequenceMsg
, the innersequenceMsg
is sent toeventloop
withp.Send
, so it cannot maintain proper order with the outersequenceMsg
.Describe the solution you'd like
improve implementation of #843. To execute the command as specified for a
sequenceMsg
orBatchMsg
of any depth of nesting, the command should be executed using a recursive function.Describe alternatives you've considered
Since the current implementation supports nesting by directly examining the result of the command invocation and nesting if statements instead of using a recursive function, the if statements must also be nested by the corresponding depth of nesting.
For now, I have not come up with an alternative.
Additional context
breaking change
Consideration should be given so that this change is not breaking. This modification changes the order in which the Command is invoked. However, in the current implementation, Command was simply executed asynchronously with
p.Send
without adhering to the order specified bytea.Sequence
ortea.Batch
. Therefore, the commands in the program that work correctly at this time are not guaranteed to be in sequence. In other words, the program works even if the order is not guaranteed. Therefore, even if this modification guarantees order, it is unlikely that a program that was already working will stop working. On the other hand, the programs that will not work correctly due to this modification are programs with bugs that happen to be working well due to the unguaranteed execution order byp.Send
andeventloop
.other information
Sequence
commands #680, fix: process nested sequence messages in order #843 are related issues and pull requests. They helped me a lot.The text was updated successfully, but these errors were encountered: