FutureLib
FutureLib copied to clipboard
Swift 3 compatibility
Hey, I'd love to see this lib available in Swift 3 so I can implement it in my project.
Thanks 😄
Swift 3 support is already in development ;) I expect to have a RC next week. Thanks for your patience.
Any chance of that Swift 3 branch being committed? Thanks.
There's now the Swift3branch which is compatible with Swift 3. This one is still in development, but should work correctly. It merely contains test code that should be removed and the source code should become more pretty.
One reason for the delay was the huge amount of changes necessary from Swift 2 to Swift 3, and some nasty data races which I was unable to fix. These occurred in the compiler generated deinit function where an Enum member variable will be accessed which has been formerly modified in a thread which seems to be not synchronised with the thread executing the deinit function. They occur only under certain circumstances, depending on how GCD reuses which threads. In most cases, those two threads happens to maintain a "Synchronizes-With" relation - in which case the data race does not occur. But this is totally random.
The thread/queue where deinit will be called is where the last strong reference to the future ceases to exist and largely depends on the circumstances and custom code. On the other hand, the thread where the Enum member variable has been modified previously is well determined, namely it's the synchronisation queue of the future. Unfortunately, there's no way for a programmer to insert proper synchronisation primitives in the deinit function (in order to synchronise with the sync queue) since this one will be generated by the compiler. So, in order for deinit to work correctly in a multi-threaded environment the compiler MUST insert the correct memory barriers themselves. I suspect, that this is not the case in all scenarios.
These data races do not occur for Optionals, though - only for that Enum type - in this case. So, the workaround was to make the Enum an Optional.
Any love for Swift packages with Swift 5?