cloudflare / template-registry

A simple API via a Worker that serves all the template content
https://developers.cloudflare.com/workers/templates
Apache License 2.0
62 stars 37 forks source link

Question: why async? #14

Open guybowden opened 4 years ago

guybowden commented 4 years ago

In this simple redirect example why are there async functions?

https://github.com/victoriabernard92/template-registry/blob/master/templates/javascript/redirect.js#L1

This could be re-written without the async keywords and appears to work the same.

function handleRequest(request) {
  return Response.redirect(someURLToRedirectTo, code)
}
addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})
/**
 * Example Input
 * @param {Request} url where to redirect the response
 * @param {number?=301|302} type permanent or temporary redirect
 */
const someURLToRedirectTo = 'https://www.google.com'
const code = 301