[swift-corelibs-dev] Asynchronous Operations

Philippe Hausler phausler at apple.com
Fri Jan 20 11:33:13 CST 2017

> On Jan 20, 2017, at 7:55 AM, Ian Partridge via swift-corelibs-dev <swift-corelibs-dev at swift.org> wrote:
> On Darwin, asynchronous usage of Operation is supported via KVO notifications.
> Because KVO is only available on Darwin platforms, swift-corelibs-foundation currently does not support asychronous Operations, and there is a comment to that effect:
> https://github.com/apple/swift-corelibs-foundation/blob/6c2afef20330681ec1f8e4e4e3e2664bfd758888/Foundation/NSOperation.swift#L50 <https://github.com/apple/swift-corelibs-foundation/blob/6c2afef20330681ec1f8e4e4e3e2664bfd758888/Foundation/NSOperation.swift#L50>
> My understanding is that it's unlikely KVO will arrive on Linux any time soon, so this leaves us with a problem in Operation.  Asynchronous usage of Operation is an important feature.
> Is there any way that we could support asynchronous operations in swift-corelibs-foundation, in the absence of KVO?

So perhaps you misunderstood my comment? What are you meaning by asynchronous operation? Technically all operations running in a queue are “asynchronous” on Darwin or on Linux. 

My commentary was about the cases where main finishes execution and the operation is not finished.

The subclassers of Operation would need to somehow notify the super-class that the operation is finished. And we would need to have a mechanism to understand if the subclasser is overriding main or start (or both?!)

> Might it be acceptable to add extra temporary public API to enable this?

There is never a thing as temporary API - it haunts us for ever ;)

I think it would be better to advocate a sound design pattern that would facilitate proper implementations on all platforms instead… Perhaps like; how does one properly use run loops in the context of Operation or dispatch. Often that is a suitable way to make things that act asynchronously without consuming another thread/queue.

> Many thanks,
> -- 
> Ian Partridge
> _______________________________________________
> swift-corelibs-dev mailing list
> swift-corelibs-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20170120/2ed30b2f/attachment.html>

More information about the swift-corelibs-dev mailing list