baidu / baidu/babylon

anyflow中 switch-case最佳实践应该怎么设计?

Open
#79 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
653
Forks
101
PR merge metrics
No merged PRs in 30d

Description

![image](https://github.com/user-attachments/assets/72dfb7e4-5a08-4ad2-9f90-227c70d2b064)
你好:
如图,在我的workflow中存在类似于Z节点的存在,需要在Z中做switch case来确认到底走哪个流程(A1/B1/C1... ,N选一)。
请问,对于Z->A1/B1/C1这种switch-case,最佳实践是怎样的?
**当前我的做法是**
1. 对于Z:
 ANYFLOW_INTERFACE(
   ANYFLOW_EMIT_DATA(int, a)
   ANYFLOW_EMIT_DATA(int, b)
   ANYFLOW_EMIT_DATA(int, b)
   )
2. 对于a1/b1/c1均有:
 ANYFLOW_INTERFACE(
   ANYFLOW_DEPEND_DATA(int, a/b/c)
   )
3. 目前我在Z的process中是这么做的:通过cancel掉其他case的depend data实现。
```
switch ($value)
{
case $a_value:
*a.emit() = 1;
b.emit().cancel();
c.emit().cancel();
break;
case $b_value:
a.emit().cancel();
*b.emit() = 2;
c.emit().cancel();
break;
case $c_value:
a.emit().cancel();
b.emit().cancel();
*c.emit() = 3;
break;
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the issue's Z-node process logic and the ANYFLOW_INTERFACE, ANYFLOW_EMIT_DATA, ANYFLOW_DEPEND_DATA, emit(), and cancel() usage shown in the example. Determine whether the existing cancellation approach is supported and what switch-case behavior should be recommended; done means a decided best-practice design or documented guidance for the N-way workflow branch.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.