<div dir="ltr">I have put on Github three concurrency libraries (<a href="https://github.com/hlovatt/Concurrency-Utilities">https://github.com/hlovatt/Concurrency-Utilities</a>):<div><br></div><div> 1. Atomic - with `get`, `set`, and `update` methods</div><div> 2. Future - with `get`, `cancel`, and `status` methods</div><div> 3. Reactive Streams - with protocols `Processor`, `Producer`, `Subscriber`, and `Subscription`, with implementations of `ForEachProducer` and `ReduceSubscriber`, and with operator `~>` for subscriptions</div><div><br></div><div>For those not familiar, Reactive Streams are a standardised form of a type of actor that have become popular and are available in multiple languages.</div><div><br></div><div>Here is Hello World in the Reactive Stream library:</div><div><br></div> let helloWorldPublisher = ForEachPublisher(sequence: "Hello, world!".characters)<br> let helloWorldSubscriber = ReduceSubscriber(into: "") { (result: inout String, next: Character) in<br> result.append(next) // Copy the string a character at a time.<br> }<br> helloWorldPublisher ~> helloWorldSubscriber // Subscribe<br><div> let helloWorldResult = helloWorldSubscriber.get ?? "Failed!" // Wait for result and check for error</div><div>
<p class="gmail-p2">Note how the arguments to <span class="gmail-s3">`</span><span class="gmail-s2">ForEachProducer</span><span class="gmail-s3">`</span> and <span class="gmail-s3">`</span><span class="gmail-s2">ReduceSubscriber</span><span class="gmail-s3">`</span> mimic those to similarly named methods in Swifts <span class="gmail-s3">`</span><span class="gmail-s2">Sequence</span><span class="gmail-s3">`</span> protocol, how <span class="gmail-s3">`</span><span class="gmail-s2">~></span><span class="gmail-s3">`</span> is evocative of the process that is occurring, and how future's <span class="gmail-s3">`</span><span class="gmail-s2">get</span><span class="gmail-s3">`</span> controls execution and error reporting.</p></div><div><br></div><div>If anyone experiments with them and provide feedback :), it would be greatly appreciated.</div><div><br></div><div>Thanks,</div><div><br></div><div> -- Howard.</div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"> -- Howard.<br></div></div>
<br><div class="gmail_quote">On 3 September 2017 at 17:36, Georgios Moschovitis <span dir="ltr"><<a href="mailto:george.moschovitis@icloud.com" target="_blank">george.moschovitis@icloud.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">That would be definitely a great addition to the language. IMO, Dart gets this right:<div><br></div><div><a href="https://www.dartlang.org/tutorials/language/futures" target="_blank">https://www.dartlang.org/<wbr>tutorials/language/futures</a></div><div><a href="https://www.dartlang.org/tutorials/language/streams" target="_blank">https://www.dartlang.org/<wbr>tutorials/language/streams</a></div><div><br></div><div>In general, I would prefer an async story like this:</div><div><br></div><div>- support coroutines / generators (yield)</div><div>- use coroutines to implement Future and Stream/Observable</div><div>- optionally provide async/await as syntax sugar for Future/Stream (or just reuse yield)</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-g.</div></font></span><div><br><div><div><div><blockquote type="cite"><div><div class="h5"><div>On 29 Aug 2017, at 4:56 AM, Howard Lovatt via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br class="m_309155721252872234Apple-interchange-newline"></div></div><div><div><div class="h5"><div dir="ltr">Many of the currently popular server side frameworks are switching to Reactive Streams:<div><br></div><div> <a href="http://en.wikipedia.org/wiki/Reactive_Streams#Adoption" target="_blank">http://en.wikipedia.org/wiki/<wbr>Reactive_Streams#Adoption</a></div><div><br></div><div>for their underlying communication, including Akka. Reactive Streams are also to become builtin to Java, as the Flow class, in version 9.</div><div><br></div><div>Would it be wise if Swift 5 also builtin Reactive Stream protocols and built its Actor implementation etc. on top of this protocol?<br><div class="gmail_extra"><br clear="all"><div><div class="m_309155721252872234gmail_signature"> -- Howard.<br></div></div><div class="m_309155721252872234gmail_signature"><br></div><div class="m_309155721252872234gmail_signature">More info on Reactive streams:</div><div class="m_309155721252872234gmail_signature"><br></div><div class="m_309155721252872234gmail_signature"> <a href="https://github.com/reactive-streams/reactive-streams-jvm/blob/v1.0.1/README.md#specification" target="_blank">https://github.com/reactive-<wbr>streams/reactive-streams-jvm/<wbr>blob/v1.0.1/README.md#<wbr>specification</a></div><div class="m_309155721252872234gmail_signature"><br></div><div class="m_309155721252872234gmail_signature"> <a href="http://bryangilbert.com/post/code/scala/akka-reactive-streams/" target="_blank">http://bryangilbert.com/<wbr>post/code/scala/akka-reactive-<wbr>streams/</a></div><div class="m_309155721252872234gmail_signature"><br></div>
<div class="gmail_quote"><br></div></div></div></div></div></div><span class="">
______________________________<wbr>_________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br></span></div></blockquote></div><br></div></div></div></div></blockquote></div><br></div>