Skip to content

Instantly share code, notes, and snippets.

@lucas-pelton
Created October 20, 2019 14:10
Show Gist options
  • Save lucas-pelton/b2bec212e37ad3cb38d4f8b249146f81 to your computer and use it in GitHub Desktop.
Save lucas-pelton/b2bec212e37ad3cb38d4f8b249146f81 to your computer and use it in GitHub Desktop.
CloudFlare worker promise race boilerplate
response = await Promise.race([
fetch('https://possibly.slow.io/' + options.token + '/get', {
method: 'POST',
body: JSON.stringify(data),
}),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Timeout')), options.timeout)
),
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment