Latest 0.9.1
Homepage https://github.com/darioalessandro/Theater
License Apache2
Platforms ios 8.0
Dependencies Starscream
Authors

Theater

Theater : iOS Actor Model Framework

Build Status
Pod Version

Writing async, resilient and responsive applications is too hard.

In the case of iOS, is because we’ve been using the wrong abstraction level: NSOperationQueues, dispatch_semaphore_create, dispatch_semaphore_wait and other low level GCD functions and structures.

Using the Actor Model, we raise the abstraction level and provide a better platform to build correct concurrent and scalable applications.

Theater is Open Source and available under the Apache 2 License.

Theater is inspired by Akka.

Twitter = @TheaterFwk

How to get started

pod 'Theater'

Actors should subclass the Actor class:

  public class Dude : Actor {

In order to "listen" for messages, actors have to override the receive method:

  override public func receive(msg : Message) -> Void {

  }

In order to unwrap the message, you can use switch

override public func receive(msg : Message) -> Void {
  switch (msg) {
    case let m as Hi:
      m.sender! ! Hello(sender: self.this)
    case is Hello:
      print("got Hello")
    default:
      print("what?")
  }
}

All messages must subclass Message:


public class Hi : Message {}

public class Hello : Message {}

Actors live inside an actor system, theater provides a default system

  let system : ActorSystem = AppActorSystem.shared

Putting in all together:

import Theater

public class Hi : Message {}

public class Hello : Message {}

public class Dude : Actor {
    override public func receive(msg : Message) -> Void {
        switch (msg) {
            case let m as Hi:
                m.sender! ! Hello(sender: self.this)
            case is Hello:
                print("got Hello")
            default:
                print("what?")
        }
    }
}

.
.
.
(inside the app delegate)

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        let system : ActorSystem = AppActorSystem.shared

        let dude1 = system.actorOf(Dude.self, name: "dude1")
        let dude2 = system.actorOf(Dude.self, name: "dude2")

        dude2 ! Hi(sender : dude1)

The output will be:

Tell = Optional("dude1") <Actors.Hi: 0x7bf951a0> dude2 
Tell = Optional("dude2") <Actors.Hello: 0x7be4bc00> dude1 
got Hello

Latest podspec

{
    "name": "Theater",
    "version": "0.9.1",
    "swift_version": "4.2",
    "summary": "Swift framework to help write async, resilient and responsive applications.",
    "description": "Writing async, resilient and responsive applications is too hard. nnIn the case of iOS, is because we've been using the wrong abstraction level: NSOperationQueues, dispatch_semaphore_create, dispatch_semaphore_wait and other low level GCD functions and structures.nnUsing the Actor Model, we raise the abstraction level and provide a better platform to build correct concurrent and scalable applications.nnTheater is Open Source and available under the Apache 2 License.nnTheater is inspired by Akka.nnTwitter = [@TheaterFwk](https://twitter.com/TheaterFwk)nn### How to get startednn- install via [CocoaPods](http://cocoapods.org)nn```rubynpod 'Theater'n```nnActors should subclass the Actor class:nn```swiftn  public class Dude : Actor {n```nIn order to "listen" for messages, actors have to override the receive method:n```swiftn  override public func receive(msg : Message) -> Void {nn  }n```nnIn order to unwrap the message, you can use switch nn```swiftnoverride public func receive(msg : Message) -> Void {n  switch (msg) {n    case let m as Hi:n      m.sender! ! Hello(sender: self.this)n    case is Hello:n      print("got Hello")n    default:n      print("what?")n  }n}n```nnAll messages must subclass Message:n```swiftnnpublic class Hi : Message {}n npublic class Hello : Message {}nn```nnActors live inside an actor system, theater provides a default systemnn```swiftn  let system : ActorSystem = AppActorSystem.sharedn```nnPutting in all together:nn```swiftnimport Theatern npublic class Hi : Message {}n npublic class Hello : Message {}n npublic class Dude : Actor {n    override public func receive(msg : Message) -> Void {n        switch (msg) {n            case let m as Hi:n                m.sender! ! Hello(sender: self.this)n            case is Hello:n                print("got Hello")n            default:n                print("what?")n        }n    }n}nn.n.n.n(inside the app delegate)nnfunc application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {n        n        let system : ActorSystem = AppActorSystem.sharedn        n        let dude1 = system.actorOf(Dude.self, name: "dude1")n        let dude2 = system.actorOf(Dude.self, name: "dude2")n        n        dude2 ! Hi(sender : dude1)n```nnThe output will be:n```swiftnTell = Optional("dude1")  dude2 nTell = Optional("dude2")  dude1 ngot Hellon```",
    "homepage": "https://github.com/darioalessandro/Theater",
    "screenshots": "https://raw.githubusercontent.com/darioalessandro/Theater/master/theaterlogo.jpg",
    "license": {
        "type": "Apache2",
        "file": "License.txt"
    },
    "authors": {
        "Dario Lencina": "[email protected]"
    },
    "social_media_url": "https://twitter.com/theaterfwk",
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/darioalessandro/Theater.git",
        "tag": "0.9.1"
    },
    "source_files": "Classes/*.swift",
    "dependencies": {
        "Starscream": [
            "~> 3.0.6"
        ]
    }
}

Pin It on Pinterest

Share This