# Async/Generator functions in CLJS - (requesting feedback!)

**URL:** https://clojureverse.org/t/async-generator-functions-in-cljs-requesting-feedback/2262
**Category:** General Questions
**Created:** [June 11, 2018, 3:50pm UTC](https://clojureverse.org/t/async-generator-functions-in-cljs-requesting-feedback/2262 "2018-06-11T15:50:11Z")
**Posts on this page:** 9
**Page:** 3

<div class="post-metadata">

### Author: ![didibus](https://clojureverse.org/user_avatar/clojureverse.org/didibus/32/951_2.png) [@didibus](https://clojureverse.org/u/didibus)
#### Post date: [November 14, 2018, 8:24am UTC](https://clojureverse.org/t/async-generator-functions-in-cljs-requesting-feedback/2262/41 "2018-11-14T08:24:11Z")

</div>

> [@thheller](#):
>
> Seems like this will be getting more relevant in the future as `async/await` will get better performance than other approaches.

Maybe I’m reading the post wrong, but what they say is they’ve improved the performance of Promises. And the charts actually even show that Promises are even faster then async/await.

---

<div class="post-metadata">

### Author: ![thheller](https://clojureverse.org/user_avatar/clojureverse.org/thheller/32/534_2.png) [@thheller](https://clojureverse.org/u/thheller)
#### Post date: [November 14, 2018, 9:09am UTC](https://clojureverse.org/t/async-generator-functions-in-cljs-requesting-feedback/2262/42 "2018-11-14T09:09:48Z")

</div>

I said “in the future”. Right now `Promise` code performs better. The coming improvements are mentioned later on in the post.

> **`async` / `await` outperforms hand-written promise code now**. The key takeaway here is that we significantly reduced the overhead of async functions — not just in V8, but across all JavaScript engines, by patching the spec

> [@](#):
>
> And we also have some nice performance advice for JavaScript developers:
> 
> - favor `async` functions and `await` over hand-written promise code, and
> - stick to the native promise implementation offered by the JavaScript engine to benefit from the shortcuts, i.e. avoiding two microticks for `await` .

---

<div class="post-metadata">

### Author: ![didibus](https://clojureverse.org/user_avatar/clojureverse.org/didibus/32/951_2.png) [@didibus](https://clojureverse.org/u/didibus)
#### Post date: [November 14, 2018, 7:28pm UTC](https://clojureverse.org/t/async-generator-functions-in-cljs-requesting-feedback/2262/43 "2018-11-14T19:28:35Z")

</div>

Interesting. I’m not sure what makes it faster then hand written Promises. Unless they mean non optimal hand written Promises.

---

<div class="post-metadata">

### Author: ![jmlsf](https://clojureverse.org/user_avatar/clojureverse.org/jmlsf/32/1271_2.png) [@jmlsf](https://clojureverse.org/u/jmlsf)
#### Post date: [November 15, 2018, 6:19pm UTC](https://clojureverse.org/t/async-generator-functions-in-cljs-requesting-feedback/2262/44 "2018-11-15T18:19:00Z")

</div>

[The article @thheller posted in August](https://mathiasbynens.be/notes/async-stack-traces) explains one reason why. The gist of it is:

> The fundamental difference between `await` and vanilla promises is that `await X()`_suspends_ execution of the current function, while `promise.then(X)`_continues_ execution of the current function after adding the `X` call to the callback chain. In the context of stack traces, this difference is pretty significant.

---

<div class="post-metadata">

### Author: ![system](https://clojureverse.org/uploads/default/original/2X/5/51079bf9e4b7d9466242c06cf1e43b9f8bd6da14.png) [@system](https://clojureverse.org/u/system)
#### Post date: [May 17, 2019, 6:19am UTC](https://clojureverse.org/t/async-generator-functions-in-cljs-requesting-feedback/2262/45 "2019-05-17T06:19:08Z")

</div>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

### Author: ![jiyinyiyong](https://clojureverse.org/user_avatar/clojureverse.org/jiyinyiyong/32/85_2.png) [@jiyinyiyong](https://clojureverse.org/u/jiyinyiyong)
#### Post date: [October 2, 2019, 5:36am UTC](https://clojureverse.org/t/async-generator-functions-in-cljs-requesting-feedback/2262/46 "2019-10-02T05:36:47Z")

</div>

Do we still have chance to have async/await in ClojureScript?

---

<div class="post-metadata">

### Author: ![thheller](https://clojureverse.org/user_avatar/clojureverse.org/thheller/32/534_2.png) [@thheller](https://clojureverse.org/u/thheller)
#### Post date: [October 2, 2019, 6:22pm UTC](https://clojureverse.org/t/async-generator-functions-in-cljs-requesting-feedback/2262/47 "2019-10-02T18:22:47Z")

</div>

Only @dnolen can answer that. His last answer was

> basically I’ve already rejected this at least 2 times over after past 3 years

> and I haven’t seen anything happen in the JavaScript world that makes me think it’s delivering enough value to take it on

and I doubt anyone will start work on it unless that has changed. It also would take quite a bit of work with lots of internal compiler changes so it might just not happen for that reason alone.

I’m still not sure it is a good idea either but given that the Browser support is now better for async/await then manual Promise code it might be time.

---

<div class="post-metadata">

### Author: ![plexus](https://clojureverse.org/user_avatar/clojureverse.org/plexus/32/6_2.png) [@plexus](https://clojureverse.org/u/plexus)
#### Post date: [October 3, 2019, 12:10am UTC](https://clojureverse.org/t/async-generator-functions-in-cljs-requesting-feedback/2262/48 "2019-10-03T00:10:04Z")

</div>



---

<div class="post-metadata">

### Author: ![jiacai2050](https://clojureverse.org/user_avatar/clojureverse.org/jiacai2050/32/2561_2.png) [@jiacai2050](https://clojureverse.org/u/jiacai2050)
#### Post date: [August 15, 2020, 9:24am UTC](https://clojureverse.org/t/async-generator-functions-in-cljs-requesting-feedback/2262/49 "2020-08-15T09:24:09Z")

</div>

Although async/await is just syntax sugar over Promise, it has two advantages:

1. emancipate programmers from chaining then or deep-nested callbacks.
2. make async error handling easy. we can have a big try catch block at the beginning of our app, errors thrown from async/await functions will go up to the upper catch.

core.async solve first advantage as well, but I struggle to handle error in thrown in different functions.  
After some search, I found [async-error](https://github.com/alexanderkiel/async-error) solve error handle issue with two macros `go-try`, `<?`. eg:

```auto

function fetchImg() {
  return Promise.reject("img");
}

function fetchCss() {
  return Promise.reject("css");
}

async function init() {
  let img = await fetchImg();
  let css = await fetchCss();
  return img + css;
}

(async function() {
  try {
    let ret = await init();
    console.log("ok = " + ret);
  } catch (e) {
    console.log("e = " + e);
  }
}());

// e = img

```

```clojure
(ns myapp.core
  (:require [async-error.core :refer-macros [go-try <?]]
            [cljs.core.async.interop :refer-macros [<p!]]))

(defn <fetch-img []
  (go-try
   (<p! (.reject js/Promise "img"))))

(defn <fetch-css []
  (go-try
   (<p! (.reject js/Promise "css"))))

(defn init []
  (go-try
    (try
      (let [img (<? (<fetch-img))
            css (<? (<fetch-css))]
        (println "ok = " (+ img css)))
      (catch js/Error e
        (println "err = " e)))))

(init)

```

```auto
err = #error {:message Promise error, :data {:error :promise-error}, :cause img}

```

[Previous page](https://clojureverse.org/t/async-generator-functions-in-cljs-requesting-feedback/2262.md?page=2)
