Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
tobr
on Jan 25, 2018
|
parent
|
context
|
favorite
| on:
Deep-copying in JavaScript
Is the `await` used in the last two examples a typo? They're not asynchronous are they?
dassurma
on Jan 25, 2018
[–]
So, it’s me being lazy and copy-pasting, but you can use await on synchronous functions, too. It’s a no-op :D
phpnode
on Jan 25, 2018
|
parent
[–]
Not a no-op, it wraps the awaited value in `Promise.resolve()`:
async function foo() { const a = await {then(resolve) { resolve(123); }}; console.log(a); } foo();
pitaj
on Jan 25, 2018
|
root
|
parent
[–]
Indeed, you don't use `await` on functions either, it's used on promises. In fact, when used on a non-promise, it still waits an extra loop cycle before resolving and continuing the async function.
Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: