Giter VIP home page Giter VIP logo

swiftactors's Introduction

Actors in Swift

This is an approach to implement actor model of concurrency in Swift.

What's included:

  • simple inbox based on Array
  • serial GCD dispatch queue, created separately for each actor
  • use ! operator to send a message
  • messages can be anything, structs preferred

See SwactorTests.swift for example usage.

What are actors?

Actor model is an approach to concurrency known in Erlang, and implemented in Scala. For JVM there is popular framework, Akka

Actor model is an approach to make massive concurrency much easier by eliminating locking and synchronization, which is hard to master and may lead to difficult to detect bugs.

Altough iOS apps are not going to tackle such problems, I found actors as a interesting abstraction over concurrent computation.

In a nutshell, actor is a small task processor with inbox to which it is accepting messages. This is why sometimes actor model is called message-passing style of concurrency. Messages are sent asynchronously, but actor is processing them one at time. Processing outcome is usually sending a message to another actor, and so on. Most likely, last actor in "chain" will be responsible for output.

Messages sent to actors are (should be) immutable, so Swift's struct are good fit, making syntax similar to Scala's case classes.

Actors can handle any type of message, and Swift's pattern matching (just like in Scala) is used inside actor.

Actors are created by extending Actor or ActorUI class and overriding receive(message: Any) method.

Example project

Look at Example weather iOS app

Contact me

swiftactors's People

Contributors

tomekc avatar

Watchers

Danny Thuering avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.