Skip to content

Another case of "async" missing in JS output #5980

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

Closed
cknitt opened this issue Feb 5, 2023 · 3 comments · Fixed by #5983
Closed

Another case of "async" missing in JS output #5980

cknitt opened this issue Feb 5, 2023 · 3 comments · Fixed by #5983
Assignees
Milestone

Comments

@cknitt
Copy link
Member

cknitt commented Feb 5, 2023

While migrating a large project to use async/await, I came across the following problem:

type data

@module("SomeModule")
external fetchData: string => promise<data> = "fetchData"

let promiseCreators = ["1", "2"]->Js.Array2.map(id => async () => await fetchData(id))

compiles to

var promiseCreators = [
    "1",
    "2"
  ].map(function (id) {
      return function (param) {
        return await SomeModule.fetchData(id);
      };
    });

which is not valid because the inner function contains an await, but is not annotated with async.

This occurs in both 10.1.2 and current master.
https://rescript-lang.org/try?version=v10.1.2&code=C4TwDgpgBAJghsOAoJABAtgexgVwDYQAUARAMqboQCy2+ExAlEhAB7AQBOAdnHlAGYRgAYwAWAEQRwAXFADOwDgEsuAcygBeAHxQwHCkrkQAPPEQ6NUYoJESpxFAWC796QxADCHCAkwc5mlAA2sQAjMQANFYATMQAugC0WgBScgB0AIIcHHAg0WnocGCESjCaOnByIFzCUIQM5VBwAO5wSs42YpKIJTAMTEA

@cristianoc
Copy link
Collaborator

cristianoc commented Feb 5, 2023

Simpler repro:

let foo = () => async y => await y

compiles to

function foo(param, y) {
  return await y;
}

cristianoc added a commit that referenced this issue Feb 6, 2023
Nested curried functions are combined into one, and the async inner function is not generated.
This PR Avoids combining nested functions when they are async.

Fixes #5980
cristianoc added a commit that referenced this issue Feb 6, 2023
Nested curried functions are combined into one, and the async inner function is not generated.
This PR Avoids combining nested functions when they are async.

Fixes #5980
@cristianoc
Copy link
Collaborator

@cknitt this should fix it: #5983

The PR should probably be ported to 10.1.
Another possible candidate fix for back-porting, though mostly harmless, is this #5982

cristianoc added a commit that referenced this issue Feb 6, 2023
Nested curried functions are combined into one, and the async inner function is not generated.
This PR Avoids combining nested functions when they are async.

Fixes #5980
@cknitt
Copy link
Member Author

cknitt commented Feb 6, 2023

@cristianoc Thanks a lot! I can confirm that this solves the original issue that I experienced in our codebase.

@cristianoc cristianoc added this to the v10.1 milestone Feb 9, 2023
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

Successfully merging a pull request may close this issue.

2 participants