Skip to content

Immediately invoked async functions lead to non-working code  #5754

Closed
@fhammerschmidt

Description

@fhammerschmidt

Consider this example:

let wrapSomethingAsync: unit => unit = () => {
  let asyncFn = async () => {
    let test = await Js.Promise.resolve("Test")
    Js.log(test)
  }

  let _ = asyncFn()
}

this works and creates the following JS

function wrapSomethingAsync(param) {
  var asyncFn = async function (param) {
    var test = await Promise.resolve("Test");
    console.log(test);
  };
  asyncFn(undefined);
}

but when I immediately invoke the async function and make it anonymous

let wrapSomethingAsync: unit => unit = () => {
  let _ = (
    async () => {
      let test = await Js.Promise.resolve("Test")
      Js.log(test)
    }
  )()
}

it compiles to

function wrapSomethingAsync(param) {
  var test = await Promise.resolve("Test");
  console.log(test);
}

which misses the async keyword somewhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions