News for hackers. Stuff that matters.
Re:I Avoid Async/Await by bin_bash on Saturday April 16, 2022 @09:00AM (#31051960)
here's a real world example I use all the time:

    const wait = (ms = 500) => new Promise(resolve => setTimeout(resolve, ms));
then:

    async function () {
      await wait(1000);
    }
Perhaps it's hard to grok but it sure is a handy one-liner.

Of course in newer versions of node we can now do:

    import {
      setTimeout,
    } from 'timers/promises';

    await setTimeout(100);
Re:I Avoid Async/Await by joe_guy on Saturday April 16, 2022 @11:44AM (#31053218)
There's no merit of what should be a project wide function being a single line instead of 3 to avoid "hard to grok" syntax.
Re:I Avoid Async/Await by deschutes on Saturday April 16, 2022 @12:28PM (#31053659)
Wait till you see the rest of javascript...
Re:I Avoid Async/Await by eurasiantiger on Saturday April 16, 2022 @05:36PM (#31056304)
Your comment is snarky and categorically dismissive. Care to explain why you have taken such an aggressive stance against JS?
Re:I Avoid Async/Await by love2read on Saturday April 16, 2022 @09:57AM (#31052363)
this works in older versions of node too:

const wait = require(‘util’).promisify(setTimeout)

Re:I Avoid Async/Await by oauea on Saturday April 16, 2022 @11:37AM (#31053144)
but not in the browser