RunJS icon indicating copy to clipboard operation
RunJS copied to clipboard

Feature Request: Top level await

Open TheNoim opened this issue 5 years ago • 14 comments

To try out things, top level await would be awesome. It is very annoying to write:

(async () => {
    async function t() {}
    await t();
})().catch(console.trace);

With top level await:

async function t() {}

await t();

TheNoim avatar Jan 21 '19 13:01 TheNoim

There's currently no official Babel plugin for top-level await. When they release one I will certainly look into adding it.

lukehaas avatar Feb 09 '19 16:02 lukehaas

However, you could wrap the input code automatically with an async function, or?

TheNoim avatar Feb 10 '19 12:02 TheNoim

Unfortunately that would result in the line-by-line output for top level code no longer being possible.

lukehaas avatar Feb 10 '19 16:02 lukehaas

Can you not calculate the offset?

TheNoim avatar Feb 10 '19 16:02 TheNoim

I'm not sure what you mean by that, but I'm certain there's no simple solution here.

lukehaas avatar Feb 10 '19 17:02 lukehaas

https://www.chromestatus.com/feature/5767881411264512#:~:text=Allow%20the%20%60await%60%20keyword%20at,modules%20and%20exposes%20implementation%20details.

Added above link to track when TLA is landing in Chromium

lukehaas avatar Aug 27 '20 08:08 lukehaas

This shipped now according to the linked docs. Any idea if this will be implemented?

hoegertn avatar Mar 25 '21 15:03 hoegertn

@hoegertn it's shipped with Chromium 89. RunJS is currently on Chromium 85. It's something I'll look further into after the upgrade. It's support is only in modules which may complicate its use in RunJS.

lukehaas avatar Mar 26 '21 08:03 lukehaas

I would really like this as well. Any news @lukehaas ?

wc-matteo avatar Nov 25 '21 16:11 wc-matteo

@wc-matteo it's currently not possible due to upstream limitations. I'm very keen to support top-level await so if anything changes this will be top priority.

lukehaas avatar Nov 25 '21 16:11 lukehaas

Top level await would make runJS so much more useful, it would become a great playground for exploring and debugging various API

timuric avatar Mar 11 '22 13:03 timuric

If you are looking for logging async functions in a convenient way, you could enable pipe operator for your convenience

const log = (fn)=>{
  fn.then(r=>console.log(r))
}

asyncFunction() |> log

timuric avatar Mar 11 '22 13:03 timuric

I would love to see this feature!

jimmyn avatar Jul 06 '22 11:07 jimmyn

That would be great indeed, are there any news?

melMass avatar Aug 13 '22 14:08 melMass

Just bought the software and this is the first issue I encounter in 30 seconds of using it... I'm sorry but it's 2023 and this is long overdue. I regret purchasing it without trying it out first.

letoast avatar Feb 15 '23 14:02 letoast

it's 2023

I liked runjs but I think there are way better alternatives now and free.

melMass avatar Feb 16 '23 04:02 melMass

it's 2023

I liked runjs but I think there are way better alternatives now and free.

@melMass any suggestions?

Stiropor avatar Mar 19 '23 18:03 Stiropor

@melMass @TheNoim latest version (2.8.0) supports top level await, so this ticket can be closed.

https://github.com/lukehaas/RunJS/releases/tag/v2.8.0

btecu avatar Mar 19 '23 19:03 btecu

@wc-matteo @timuric @jimmyn @hoegertn @letoast Top-level await is now supported. However, it's not compatible with displaying runtime values. For that reason, it is not enabled by default. You can enable top-level await from the settings:

Screenshot 2023-03-20 at 10 15 18

lukehaas avatar Mar 20 '23 10:03 lukehaas