d at domenic.me (2015-02-17T17:58:57.823Z)
Yes, the non-overlapping way to write it IMO would be to isolate the
rejection on errors to a function:
```
let watchError = (client) => new Promise((resolve, reject) => client.on("error", reject));
// as a plain promise
function fetchish(){
    let client = new Client;
    return Promise.race([watchError(client), client.get()]).then(JSON.parse));
}
// as an async function
async function fetchish(){
     let client = new Client();
     let result = await Promise.race([client.get(), watchError(client)]);
     return JSON.parse(result);
}
```
Yes, the non-overlapping way to write it IMO would be to isolate the rejection on errors to a function: ``` let watchError = (client) => new Promise((resolve, reject) => client.on("error", reject)); // as a plain promise function fetchish(){ let client = new Client; return Promise.race([watchError(client), client.get()]).then(JSON.parse)); } // as an async function async function fetchish(){ let client = new Client(); let result = await Promise.race([client.get(), watchError(client)]); return JSON.parse(result); } ``` On Wed, Feb 4, 2015 at 1:16 AM, Andrea Giammarchi < andrea.giammarchi at gmail.com> wrote: > to be honest that looks more like an all-in (good old events in the house) > ... put a generator somewhere, please! > </ignore-me> > > I wonder if actually fetchish shouldn't be directly a Promise instead, > feels like overlapping. Just random thoughts, curious to see more mixed > async patterns in the real world > > Best Regards > > On Tue, Feb 3, 2015 at 8:26 PM, Kevin Smith <zenparsing at gmail.com> wrote: > >> I would think that a hypothetical `client.get` method would reject when >> an error occurred, so that you wouldn't need to attach an "error" handler. >> >> That said, you can also freely mix promises with await and async: >> >> async function fetchish() { >> >> let text = await new Promise((resolve, reject) => { >> >> let client = new Client; >> client.on("error", reject); >> resolve(client.get()); >> }); >> >> return JSON.parse(text); >> } >> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150204/eeef4466/attachment.html>