ProtoFlux:Async For: Difference between revisions

From Resonite Wiki
add info, example, how it works
clean
 
(6 intermediate revisions by 3 users not shown)
Line 10: Line 10:
|Outputs=
|Outputs=
[
[
{"Name": "LoopStart", "Type":"SyncResumption"},
{"Name": "LoopStart", "Type":"AsyncCall"},
{"Name": "LoopIteration", "Type":"SyncResumption"},
{"Name": "LoopIteration", "Type":"AsyncCall"},
{"Name": "LoopEnd", "Type":"Continuation"},
{"Name": "LoopEnd", "Type":"Continuation"},
{"Name": "Iteration", "Type":"int"}
{"Name": "Iteration", "Type":"int"}
Line 17: Line 17:
|}}
|}}


ASync For is a protoflux node that will do a bunch of async tasks in order in an Async context, waiting for each task to be done before moving to the next one. This is useful if you want to do a bunch of [[ProtoFlux:GET String|GET String]] requests but you need to wait for the previous one to be done before doing the next, for a specified number of times. This does not behave the same as using a [[ProtoFlux:Start ASync Task|Start ASync Task]] on every [[ProtoFlux:For|For loop]] iteration or even before the for loop using a [[ProtoFlux:Start ASync Task|Start ASync Task]].
The '''Async For''' node is used to perform looping operations by allowing one to fire impulses a set amount of times. It is the [[async]] variant of the [[ProtoFlux:For|For]] node.


== Inputs ==
== Inputs ==


=== * ===
=== * ([[Impulses#ASync|IAsyncOperation]]) ===


Start the execution of this node.
Begin the for loop.


=== Count ([[Type:Int|int]]) ===
=== Count ([[Type:Int|int]]) ===


How many times to execute LoopIteration ([[Impulses#ASync|SyncResumption]])
The amount of times to trigger <code>LoopIteration</code>. Will not trigger any iterations if less than 1.


=== Reverse ([[Type:Bool|bool]]) ===
=== Reverse ([[Type:Bool|bool]]) ===


Whether to start at Count ([[Type:Int|int]]) and go backwards.
If <code>True</code>, the <code>Iteration</code> output will start at <code>Count - 1</code> and go down towards <code>0</code>.


== Outputs ==
== Outputs ==


=== LoopStart ([[Impulses#ASync|SyncResumption]]) ===
=== LoopStart ([[Impulses#ASync|AsyncCall]]) ===


=== LoopIteration ([[Impulses#ASync|SyncResumption]]) ===
Fires after <code>*</code> is pulsed and before any iterations are done. Will be pulsed even if <code>Count < 1</code>.


Fires while the loop is running and after the previous LoopIteration ([[Impulses#ASync|SyncResumption]]) or LoopStart ([[Impulses#ASync|SyncResumption]]) has finished.
=== LoopIteration ([[Impulses#ASync|AsyncCall]]) ===
 
Fires for each iteration of the loop. This impulse is triggered <code>Count</code> amount of times and the next iteration will only be fired once the current iteration's [[context]] is finished.


=== LoopEnd ([[Impulses|Continuation]]) ===
=== LoopEnd ([[Impulses|Continuation]]) ===


Fires once the loop has finished all LoopIteration ([[Impulses#ASync|SyncResumption]]) in order.
Fires after the final <code>LoopIteration</code> completes execution.


=== Iteration ([[Type:Int|int]]) ===
=== Iteration ([[Type:Int|int]]) ===


The current iteration of the loop.
For each <code>LoopIteration</code>, this output is set to be the index of the iteration for said iteration's context. By default, this will start at <code>0</code> and increment until <code>Count - 1</code> unless <code>Reverse</code> is <code>True</code>.


== Examples ==
== Examples ==
<gallery widths=480px heights=480px>
File:Protoflux_example_ASync_For.webp|ASync For being used to do X cloud variable reads in order.
File:Protoflux_example_ASync_For2.webp|ASync For being used to do X web requests in order.
</gallery>


[[Category:ProtoFlux:Flow:Async]]
[[Category:ProtoFlux:Flow:Async]]

Latest revision as of 21:51, 13 December 2024

Async For
*
LoopStart
Count
LoopIteration
Reverse
LoopEnd
Iteration
Async

The Async For node is used to perform looping operations by allowing one to fire impulses a set amount of times. It is the async variant of the For node.

Inputs

* (IAsyncOperation)

Begin the for loop.

Count (int)

The amount of times to trigger LoopIteration. Will not trigger any iterations if less than 1.

Reverse (bool)

If True, the Iteration output will start at Count - 1 and go down towards 0.

Outputs

LoopStart (AsyncCall)

Fires after * is pulsed and before any iterations are done. Will be pulsed even if Count < 1.

LoopIteration (AsyncCall)

Fires for each iteration of the loop. This impulse is triggered Count amount of times and the next iteration will only be fired once the current iteration's context is finished.

LoopEnd (Continuation)

Fires after the final LoopIteration completes execution.

Iteration (int)

For each LoopIteration, this output is set to be the index of the iteration for said iteration's context. By default, this will start at 0 and increment until Count - 1 unless Reverse is True.

Examples