You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's probably a good idea to await on all promises before the function returns, to prevent the control flow from becoming too confusing, but this isn't strictly necessary
from that previous proposal it seems quite clear that the language won't consider such a feature, it would be a library function, and we'd like to see widespread use of such third party libraries before we consider them in the standard library.
Overview
Given the following program that needs to be optimized:
We would like to have the ability to mark any function that can run asynchronously, in a separate goroutine:
With a feature like this, library authors would be able to easily provide speedups for their users simply by annotating non-racy functions.
Older versions of Go will gracefully ignore this
//go:async
annotation and run the functions serially, like before.Users would not need to do anything to receive these benefits.
Mechanism
Upon encountering a function marked as
//go:async
, the compiler should generate a wrapper function that accepts and returns promises:Any place where a
//go:async
function is called directly should be rewritten to call the generated wrapper instead:Any use of a returned promise, other than storing to a variable or passing to another async function, must be rewritten to be awaited on:
Any parameters passed to an async function call must be wrapped inside a promise
It's probably a good idea to await on all promises before the function returns, to prevent the control flow from becoming too confusing, but this isn't strictly necessary
The text was updated successfully, but these errors were encountered: