News for hackers. Stuff that matters.
Re:Await in Rust by amelius on Monday August 12, 2019 @01:19PM (#20677566)
And so all library functions should be async by default? And if everything is async, then shouldn't synchronous programming require the extra keyword instead of the other way around?
Re:Await in Rust by Sharlin on Monday August 12, 2019 @01:24PM (#20677638)
No. A function that makes no async calls has no reason to be marked async.
Re:Await in Rust by amelius on Tuesday August 13, 2019 @02:53AM (#20683393)
And if someone wants to add an async call later, all callers need to change too.
Re:Await in Rust by Sharlin on Tuesday August 13, 2019 @03:44AM (#20683613)
Only if the function "leaks" the async-ness instead of containing it (that is, waiting on any async calls synchronously). But yes, making a function async is a backward-incompatible change, just like manually changing the return type from `T` to `Future<T>`.
Re:Await in Rust by amelius on Tuesday August 13, 2019 @04:05PM (#20689682)
Ok let me phrase it differently. If you have some library function that does some IO (for example) and you want to make it as useful as possible, would you declare it async or not? If you make it blocking, then you'd ruin any opportunity to have it called from async functions (because they don't want to be blocked). Therefore, you'd make it async. So that means that all IO library routines will become async, and possibly a lot of others too. Wouldn't it make more sense to have async be the default?
Re:Await in Rust by laughinghan on Tuesday August 13, 2019 @08:52PM (#20691759)
But when all those IO functions are rewritten to be async, their public names can be different. The sync versions needn't change names, so none of the callers would need to change. Nor would the sync versions need to duplicate code, because they can just be thin wrappers that call and wait on their async counterparts. (Note that this wouldn't be possible in JS.)