[swift-evolution] New async keyword usage

Trevör Anne Denise trevor.annedenise at icloud.com
Sat Aug 26 07:10:48 CDT 2017


Thinking about it, wouldn't hiding the implementation of Future<T> have the advantage of preventing people from returning Futures from functions ?

This would allow to write this:
func foo() async -> Future<SomeType> {
	let futureValue = Future { await someOtherFunc() }
	doSomethingElse()
	return futureValue
}

As this:
func foo() async -> SomeType {
	let futureValue = async someOtherFunc()
	doSomethingElse()
	return futureValue
}

Internally compiler would add an await at return:
func foo() async -> SomeType {
	let futureValue = async someOtherFunc()
	doSomethingElse()
	return await futureValue
}

With this syntax it would seem useless to return Future from a function ! Wouldn't it also avoid to skip some thread safety checks that would be required by Future being publicly implemented as a class ?

What do you think about it ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170826/1c9fcdc6/attachment.html>


More information about the swift-evolution mailing list