Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

My web scripting language, https://hyperscript.org, tries to hide the difference between sync and async by resolving promises in the runtime. My theory is that this is something that web script writers should not be concerned with (this theory makes more sense when you consider hyperscript is a companion to htmx, and favors a particular approach to scripting[1].)

  on click
    fetch /whatever as json
    put the result's data into #some-div
    wait 2s
    put '' into #some-div
You don't have to mark the script as sync or async, and the runtime will resolve everything for you, making everything feel like synchronous scripting.

This obviously has limitations and foot guns, but it works reasonably well for light scripting. More info here:

https://hyperscript.org/docs/#async

And the implementation of it in the runtime here:

https://github.com/bigskysoftware/_hyperscript/blob/c81b07ce...

https://github.com/bigskysoftware/_hyperscript/blob/c81b07ce...

--

[1] - https://htmx.org/essays/hypermedia-friendly-scripting/



I'm curious how you would you do something like the following? Is that just not supported?

    const promise1 = job1();
    const promise2 = job2();
    const [result1, result2] = Promise.all(promise1, promise2);


If you want job1 and job2 to be executed in parallel, you could do this:

  set result to [job1(), job2()]
  set result1 to the first result
  set result2 to the last result
The array expression will wait until all promise values resolve.

This isn't really what hyperscript is designed for, however: its async behavior is designed instead to take the async/sync distinction (and callback hell) out of "normal" DOM scripting. If you have sophisticated async needs then JavaScript is probably a better option. The good news is that hyperscript can call JavaScript functionality in the normal way, so that is an easy option if hyperscripts behavior isn't sufficient for your needs.


Thanks for the reply. I can understand that the purpose here isn't to be as powerful as JavaScript, but rather to be simpler and easier. That being said, is there a way to achieve the below or is that beyond the limits?

    const result = Promise.race(job1(), job2());


You can't achieve that with the intended semantics directly in hyperscript, because it will resolve all argument promises before invoking Promise.race()

You could move that out to JavaScript and then call that function from hyperscript:

  set result to jsPromiseRace()
it could also be done as inline js:

  js
    return Promise.race(job1(), job2());
  end
  log the result
but I think if you are writing this style of code it makes more sense to just kick out to JavaScript for it.


You could imagine an hypothetical language with implicit awaits but explicit forks:

    const promise1 = async job1();
    const promise2 = async job2();
    const [result1, result2] = Promise.all(promise1, promise2);




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: