Giter Site home page Giter Site logo

Comments (3)

bhouston avatar bhouston commented on June 11, 2024 1

@DennisSmolek I have implemented support for ForLoops and Sequences via waiting for downstream evaluation. It works well:

#75

from behave-graph.

DennisSmolek avatar DennisSmolek commented on June 11, 2024

Following up,

You would know better than I do (especially because I rarely touch Unreal)

but I was curious about the scenario you described, as it’s similar to common JS for loops being synchronous, thus “waiting”.

I remember all the headaches when things like async http calls became standard and code wasn’t ready for non-blocking..

But all the discussions I’ve found seem to say it’s as I expected and non-blocking:

https://forums.unrealengine.com/t/forloop-is-non-blocking-learn-it-the-hard-way/59127

https://forums.unrealengine.com/t/waiting-for-to-finish-before-continuing-foreach-loop/382460

there’s some stuff about frame execution and a few videos where people create their own to add a delay, but I couldn’t find anything about a “wait”

again I could be totally wrong and just didn’t dig deep enough

from behave-graph.

bhouston avatar bhouston commented on June 11, 2024

It is complex.

The problem is that you need to cause the downstream graph from loopBody to fully execute (at least the non-async nodes) before you fire it again. The reason you need to do this is otherwise you could have two loopBodies executing at exactly the same time. Given my current implementation that is a work queue, if you fired them all immediately you would have a series of items immediately inserted into the work queue basically all being the same -- loopBody.

This can not be how Unreal Engine Blueprints work. Because their for-loop construct actually supports "breaking" the loop. In order to support breaking the loop, you can not immediately schedule all loopBody iterations for execution -- or you run into the problem you now need to cancel scheduled tasks, which is basically just the same problem I am trying to solve but in a different way.

I believe that the for-loop node waits for the non-async execution of loopBody before triggering that subgraph to evaluate again. This would allow for one to break the loop. I believe that it doesn't wait across an async node though, like Delay. If you have a for-loop with a delay node in the loopBody subgraph, it will not wait for anything after the delay node.

This is what I was thinking of implementing.

So basically I will support something akin to this:

const startIndex = 0;
const endIndex = 4;

for( let index = startIndex; index < endIndex; index ++ ) {
  loopBody( index ); // note: no await here.
}

But just like JavaScript if you add an async call within the loopBody function, the for-loop will not wait for it, but if you avoid async nodes, it will wait for them.

If you put this loopBody into the above for-loop,

async function loopBody( index: number ) {
  console.log( `start: ${index}` );
  await sleep( 1000 );
  console.log( `end: ${index}` );
}

You will get this output:

start: 0
start: 1
start: 2
start: 3
end: 0
end: 1
end: 2
end: 3

But if you put this body into the for loop above:

function loopBody( index: number ) {
  console.log( `start: ${index}` );
  console.log( `end: ${index}` );
}

You will get this output:

start: 0
end: 0
start: 1
end: 1
start: 2
end: 2
start: 3
end: 3

I am looking to replicate exactly this behavior. I want a standard for loop and if you put in async nodes into it, it will not wait for them.

from behave-graph.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.