Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: parallel map #8

Closed
francescoagati opened this issue Dec 20, 2022 · 5 comments
Closed

examples: parallel map #8

francescoagati opened this issue Dec 20, 2022 · 5 comments

Comments

@francescoagati
Copy link

hi,
there is an example of parallel map node implementation?

something like this https://flows.nodered.org/node/node-red-contrib-wait-paths

@GabiGrin
Copy link
Contributor

GabiGrin commented Jan 9, 2023

hey @francescoagati, sorry this took so long!
In Flyde this works out of the box; if a part has 2 different inputs, and they are not optional, it'll wait for both inputs to receive data before continuing.
You can see this live in https://www.flyde.dev/playground/bmi/ - it waits for both prompts to finish before executing. It would do that even if they were async.
You can change the code to return a delayed promise and see that in action

  1. double click one of the prompts
  2. enter
new Promise(
    res => setTimeout(
        () => res(prompt('What is your height (in cm)?'))
    ), 10000
)

And see if it will wait the full 10 seconds before continuing.

If you need more advanced behavior you can write a custom part. Until better documentation exists you can check any of the standard library parts at https://github.com/FlydeHQ/flyde/tree/main/stdlib/parts

And as I'm not experienced with https://flows.nodered.org/node/node-red-contrib-wait-paths, if you mean something else please let me know and I'll provide an example :)

@GabiGrin
Copy link
Contributor

Hey @francescoagati, I've made many improvements to the extension since, and one of them being a few templates to choose from, one of them looping through the responses of 2 API calls and merging them into a new object:

Kapture 2023-04-17 at 22 26 19

If you try it, let me know what you think!

@francescoagati
Copy link
Author

francescoagati commented Apr 17, 2023

hey thanks,
i have try but i get this error with a simple flow

ode_modules/@flyde/resolver/dist/resolver/resolve-dependencies/resolve-dependencies.js:37
const refPartIds = part.instances
^
TypeError: Cannot read property 'instances' of undefined

with this code

const {loadFlow} = require('@flyde/runtime');
const executeFlow = loadFlow('./hello.flyde');
executeFlow() // executeFlow can also receive inputs, and other advanced configuration, more on that in the next steps
.then(({message}) => console.log(message))

@GabiGrin
Copy link
Contributor

Hey @francescoagati, thanks for trying out that quick!
Please try:

const {loadFlowByPath} = require('@flyde/runtime');
const executeFlow = export function loadFlowByPath<Inputs>(
('./hello.flyde');

Docs need some update after the latest major refactoring :)

Also, .then(({message}) => console.log(message)). won't work.
You can try:

const executeFlow = loadFlowByPath('hello.flyde');
const result  = executeFlow({} ,{
    onOutputs: (outputs,data) => {
        console.log('............')
        console.log(outputs);
        console.log(data);

    }
})

Flyde required users to explicitly say what output pins cause the part to be completed (see https://www.flyde.dev/docs/lifecycle/). I've now added implicit completion, which the templates use, but it broke the output generation. Going to fix that soon!

@GabiGrin
Copy link
Contributor

@francescoagati forgot to update that a fix was published

looking forward for your feedback and thanks for the patience in such an early stage of the project :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants