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

Supporting async functions in function map #11

Open
th1j5 opened this issue Apr 27, 2020 · 4 comments
Open

Supporting async functions in function map #11

th1j5 opened this issue Apr 27, 2020 · 4 comments

Comments

@th1j5
Copy link
Contributor

th1j5 commented Apr 27, 2020

First of all: I'm glad RocketRML support functions (and I'm putting them to good use).

But, I have a case where I would need to use an async function (details under) and I've seen this is not (yet) supported.
To illustrate:
this is a literal coming from a function: "[object Promise]"
obviously not the expected output.

Why an async function:

My function can only give results if something is loaded from the internet, thus using some async magic.

Why I think this should be feasible (without looking at the actual code :) :

The library functions are already async:

await parser.parseFileLive(mapfile,inputFiles,options);

I was thinking about just placing await before the function executions,
but I did not yet have a look at your actual code to see where this would happen and how much more work this would give.
And even more, if this is the desired path to go (using await).

@th1j5
Copy link
Contributor Author

th1j5 commented Apr 27, 2020

I've had a look at your code structure and can already say what functions wile become async if this may be done and this may be done by just placing await before every function which becomes async.
If this may be done like so, I'll open a pull request.

Do you know if this would affect you're code negatively? (I would expect not, since I think the await does not affect the sync functions and would only be helpful for a user defined function in options.function)

Functions affected according to first research:

  • function.js
    • executeFunction
  • helper.js
    • subjFunctionExecution
  • parser.js
    • handleSingleMapping
    • iterateFile
    • doObjectsMappings
    • parseFile
  • index.js
    • process

@ThibaultGerrier
Copy link
Collaborator

Hi!

Thank you for your issue. I definitely agree that async functions should be supported.

As you suggested implementing that should just be a matter of adding async to a bunch of function declarations and a bunch of awaits to function calls. I don't think it would negatively impact other aspects of the code.

The one concern I might have, is a loss of performance for mapping huge datasources (huge input files), as returning and awaiting lots of promises might affect performance. This would need to be tested. (even if it did affect performance, the difference is probably not be very noticable and so no reason to not support the feature).

Nevertheless, I definitely want to support that. I should have the feature within a few days. If you do want to try it out yourself and submit a pull request, you are very welcome to do so, just message me again:)

Thanks

@th1j5
Copy link
Contributor Author

th1j5 commented Apr 28, 2020

This is being worked on in PR #12 ,
but when the first working implementation is merged, the following will probably not yet addressed:

  • Performance when having lots of promises (comparison?)
  • Performance when doing async funtions in synchronous style by using await everywhere
    • This could be solved on some loop level by writing an async friendly loop (see comment )

@ThibaultGerrier
Copy link
Collaborator

published in v1.7.0

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