A common mistake for async beginners to make is using this library. I propose that this library is a proof-of-concept and should not be used in production code. In particular:
- The
scope_and_block API prevents composability, meaning your function cannot be called in an async function. But there is no compiler error to prevent this, so users can easily make the mistake of blocking the thread, which leads to difficult-to-debug deadlocks.
- Even if one uses this API correctly, it is borderline useless, because it can only be used at the top level, and at that level it’s typically very easily to just make your data '
static anyway. Using it also makes it much harder to refactor an async function.
- The
scope API is unsafe, which is good, but I have multiple times seen people claim that they’re using it in a safe manner, when they are in fact not. The truth is that because you can’t control what the caller does with the future, it is in fact impossible to correct use in an async function without making the async fn itself unsafe, which just forwards the easily-misunderstood safety preconditions to the caller. Of course, you could always heap allocate 'static data, but at that point you may as well just Arc it and this crate becomes unnecessary.
Given these points, I believe this crate should clearly advertise that it is not recommended for use for purposes other than education in the README and documentation.
A common mistake for async beginners to make is using this library. I propose that this library is a proof-of-concept and should not be used in production code. In particular:
scope_and_blockAPI prevents composability, meaning your function cannot be called in an async function. But there is no compiler error to prevent this, so users can easily make the mistake of blocking the thread, which leads to difficult-to-debug deadlocks.staticanyway. Using it also makes it much harder to refactor an async function.scopeAPI isunsafe, which is good, but I have multiple times seen people claim that they’re using it in a safe manner, when they are in fact not. The truth is that because you can’t control what the caller does with the future, it is in fact impossible to correct use in anasyncfunction without making theasync fnitselfunsafe, which just forwards the easily-misunderstood safety preconditions to the caller. Of course, you could always heap allocate'staticdata, but at that point you may as well justArcit and this crate becomes unnecessary.Given these points, I believe this crate should clearly advertise that it is not recommended for use for purposes other than education in the README and documentation.