Search code examples
swiftasynchronousgrand-central-dispatchopenwhisk

Create asynchronous Action in Swift


I've been trying to follow some of the examples to build actions for openwhisk. Unfortunately, most of the examples are written in JS, so I had to rewrite them in Swift. This worked out pretty well until I wanted to write asynchronous actions.

The first problem I encountered is the GCD. Openwhisks Swift-implementation runs on linux, so in order to use the GCD one would need to import the libdispatch library. Of course, I cannot modify the modules that openwhisk loads in its Swift runtime. Eventually I stumbled across the IBM Bluemix Sandbox, where I learned that there is a Dispatch module which should provide access to GCD like functionality. However, while I can create queues, dispatch-time, closures etc., I could not figure out how to actually dispatch it. dispatch_async, dispatch_after etc. are all unknown symbols.

While I am still unable to solve the first problem, I struggle with the Whisk API. In JS, there is a whisk.async() and whisk.done() command. In Swift there isn't.

Regards, Victor


Solution

  • As you have pointed out, OpenWhisk runs Swift actions in Linux containers. Linux support for both Foundation and libdispatch is still partial, probably at least for another few months. OpenWhisk regularly updates the snapshot version of Swift 2.2 that is used to run actions, but we are essentially dependent on the general progress of Swift on Linux.

    We haven't yet finalized the design of the Swift equivalent to the JavaScript whisk API. It is not necessarily the case that constructs will map one-to-one across languages. Asynchronous actions, for instance, are likely to rely on libdispatch constructs in Swift.