Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit981aea1

Browse files
authored
feat: add allow_async? flag to compose DSL (#256)
Adds the allow_async? flag to the compose DSL to control whethercomposed reactors can run their steps asynchronously.- Add allow_async? field to Reactor.Dsl.Compose struct (defaults to true)- Update DSL schema to include allow_async? option with documentation- Modify Builder.Compose to pass allow_async? to Step.Compose- Update Step.Compose to respect allow_async? when calling Reactor.run- Add comprehensive tests in test/reactor/dsl/compose_test.exs- Update documentation with usage examplesWhen allow_async? is true (default), the composed reactor runs withasync?: true, allowing concurrent step execution. When false, it runswith async?: false, forcing synchronous execution.Closes#22
1 parentd2a2ee1 commit981aea1

File tree

6 files changed

+401
-3
lines changed

6 files changed

+401
-3
lines changed

‎documentation/dsls/DSL-Reactor.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,15 @@ Compose another Reactor into this one.
638638

639639
Allows place another Reactor into this one as if it were a single step.
640640

641+
####Example
642+
643+
compose:create_user, UserReactor do
644+
argument:name, input(:user_name)
645+
argument:email, input(:user_email)
646+
allow_async? false
647+
end
648+
649+
641650

642651
###Nested DSLs
643652
*[argument](#reactor-compose-argument)
@@ -659,6 +668,7 @@ Allows place another Reactor into this one as if it were a single step.
659668
| Name| Type| Default| Docs|
660669
|------|------|---------|------|
661670
|[`description`](#reactor-compose-description){: #reactor-compose-description }|`String.t`|| An optional description for the step.|
671+
|[`allow_async?`](#reactor-compose-allow_async?){: #reactor-compose-allow_async? }|`boolean`|`true`| Whether the composed reactor is allowed to run its steps asynchronously.|
662672
|[`async?`](#reactor-compose-async?){: #reactor-compose-async? }|`boolean`|`true`| Whether the composed steps should be run asynchronously.|
663673

664674

‎lib/reactor/builder/compose.ex‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ defmodule Reactor.Builder.Compose do
1111
aliasReactor.{Builder,Error.Internal.ComposeError}
1212

1313
@opt_schemaSpark.Options.new!(
14+
allow_async?:[
15+
type::boolean,
16+
required:false,
17+
default:true,
18+
doc:"Whether the composed reactor is allowed to run its steps asynchronously"
19+
],
1420
guards:[
1521
type:{:list,{:protocol,Reactor.Guard.Build}},
1622
required:false,
@@ -40,7 +46,7 @@ defmodule Reactor.Builder.Compose do
4046
Builder.add_step(
4147
reactor,
4248
name,
43-
{Reactor.Step.Compose,reactor:inner_reactor},
49+
{Reactor.Step.Compose,reactor:inner_reactor,allow_async?:options[:allow_async?]},
4450
arguments,
4551
async?:options[:async?],
4652
guards:options[:guards]||[],

‎lib/reactor/dsl/compose.ex‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ defmodule Reactor.Dsl.Compose do
55
See the `d:Reactor.compose`.
66
"""
77
defstruct__identifier__:nil,
8+
allow_async?:true,
89
arguments:[],
910
async?:nil,
1011
description:nil,
@@ -16,6 +17,7 @@ defmodule Reactor.Dsl.Compose do
1617

1718
@typet::%Dsl.Compose{
1819
__identifier__:any,
20+
allow_async?:boolean,
1921
arguments:[Dsl.Argument.t()|Dsl.WaitFor.t()],
2022
async?:nil|boolean,
2123
description:nil|String.t(),
@@ -32,6 +34,15 @@ defmodule Reactor.Dsl.Compose do
3234
Compose another Reactor into this one.
3335
3436
Allows place another Reactor into this one as if it were a single step.
37+
38+
## Example
39+
40+
compose :create_user, UserReactor do
41+
argument :name, input(:user_name)
42+
argument :email, input(:user_email)
43+
allow_async? false
44+
end
45+
3546
""",
3647
args:[:name,:reactor],
3748
target:Dsl.Compose,
@@ -64,6 +75,14 @@ defmodule Reactor.Dsl.Compose do
6475
The reactor module or struct to compose upon.
6576
"""
6677
],
78+
allow_async?:[
79+
type::boolean,
80+
required:false,
81+
default:true,
82+
doc:"""
83+
Whether the composed reactor is allowed to run its steps asynchronously.
84+
"""
85+
],
6786
async?:[
6887
type::boolean,
6988
required:false,
@@ -80,6 +99,7 @@ defmodule Reactor.Dsl.Compose do
8099

81100
defbuild(step,reactor)do
82101
Builder.compose(reactor,step.name,step.reactor,step.arguments,
102+
allow_async?:step.allow_async?,
83103
async?:step.async?,
84104
description:step.description,
85105
guards:step.guards

‎lib/reactor/executor/step_runner.ex‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,8 @@ defmodule Reactor.Executor.StepRunner do
452452
current_step:step,
453453
concurrency_key:concurrency_key,
454454
current_try:current_try,
455-
retries_remaining:retries_remaining
455+
retries_remaining:retries_remaining,
456+
async?:state.async?
456457
})
457458
|>Map.put(:current_step,step)
458459
|>Map.put(:concurrency_key,concurrency_key)

‎lib/reactor/step/compose.ex‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ defmodule Reactor.Step.Compose do
1414
@impltrue
1515
defrun(arguments,context,options)do
1616
reactor=Keyword.fetch!(options,:reactor)
17+
allow_async?=Keyword.get(options,:allow_async?,true)
18+
19+
# Child reactor can only run async if both parent allows async AND allow_async? is true
20+
# Use the context.async? field which contains the parent reactor's async state
21+
parent_async?=Map.get(context,:async?,true)
22+
child_async?=parent_async?andallow_async?
1723

1824
Reactor.run(reactor,arguments,context,
1925
concurrency_key:context.concurrency_key,
20-
async?:options[:async?]||false
26+
async?:child_async?
2127
)
2228
end
2329

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp