{"id":18650956,"url":"https://github.com/jkrumow/actorkit","last_synced_at":"2026-03-10T02:31:08.408Z","repository":{"id":35862296,"uuid":"40147341","full_name":"jkrumow/ActorKit","owner":"jkrumow","description":"A lightweight actor framework in Objective-C.","archived":false,"fork":false,"pushed_at":"2023-05-01T10:45:37.000Z","size":703,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T15:08:02.888Z","etag":null,"topics":["actors","actors-supervision","supervision"],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jkrumow.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-08-03T20:51:20.000Z","updated_at":"2023-05-01T10:44:25.000Z","dependencies_parsed_at":"2024-11-07T06:47:43.668Z","dependency_job_id":"fa661e54-982b-450b-ac1e-5c4a6224ee5e","html_url":"https://github.com/jkrumow/ActorKit","commit_stats":{"total_commits":406,"total_committers":4,"mean_commits":101.5,"dds":"0.25369458128078815","last_synced_commit":"e9124971777e74c04ebdbe1f7e71113d6d15b22d"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jkrumow%2FActorKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jkrumow%2FActorKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jkrumow%2FActorKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jkrumow%2FActorKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jkrumow","download_url":"https://codeload.github.com/jkrumow/ActorKit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248431313,"owners_count":21102180,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["actors","actors-supervision","supervision"],"created_at":"2024-11-07T06:47:33.975Z","updated_at":"2026-03-10T02:31:03.357Z","avatar_url":"https://github.com/jkrumow.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ActorKit\n\n[![Version](https://img.shields.io/cocoapods/v/ActorKit.svg?style=flat)](http://cocoadocs.org/docsets/ActorKit)\n[![License](https://img.shields.io/cocoapods/l/ActorKit.svg?style=flat)](http://cocoadocs.org/docsets/ActorKit)\n[![Platform](https://img.shields.io/cocoapods/p/ActorKit.svg?style=flat)](http://cocoadocs.org/docsets/ActorKit)\n[![CI Status](http://img.shields.io/travis/jkrumow/ActorKit.svg?style=flat)](https://travis-ci.org/jkrumow/ActorKit)\n\nA lightweight actor framework in Objective-C.\n\n## Features\n\n* Actors\n* Actor Pools\n* Synchronous and asynchronous invocations\n* Promises\n* Notification subscription and publication\n* Supervision\n* Linking\n\n## Requirements\n\n* iOS 8.0\n* watchOS 2.0\n* tvOS 9.0\n* OS X 10.10\n\n## Installation\n\nActorKit is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'ActorKit'\n```\n\n## Usage\n\nAny object derived from `NSObject` can be turned into an actor by importing `\u003cActorKit/ActorKit.h\u003e`.\n\n```objc\n`#import \u003cActorKit/ActorKit.h\u003e`\nWorker *worker = [[Worker alloc] initWithName:@\"Bee\"];\nNSMutableArray *array = [NSMutableArray new];\n```\n\nAs soon as you start sending messages to them as described below they will behave like actors automatically. There is nothing else you have to do.\n\n### Sending Messages to Actors\n\nTo send a synchronous message to the actor precede the call with `sync`:\n\n```objc\nBOOL success = [worker.sync doSomething];\n```\n\nSend an asynchronous message to the actor use `async`:\n\n```objc\n[array.async removeAllObjects];\n```\n\n### Publishing notifications to other actors\n\nPublish a notification with a payload:\n\n```objc\n[self publish:@\"notification\" payload:@5];\n```\n\n### Subscribing to notifications from other actors\n\nTo subscribe to a notification set the notification name and a selector which takes the notification's payload as an argument:\n\n```objc\n[worker subscribe:@\"notification\" selector:@selector(handler:)];\n\n- (void)handler:(NSNumber *)number\n{\n    // ...\n}\n```\n\nTo unsubscribe from a notification:\n\n```objc\n[worker unsubscribe:@\"notification\"];\n```\n\nBefore destroying an actor you should unsubscribe from all notifications.\n\n### Actor Pools\n\nThe class `TBActorPool` is basically a proxy actor which mananges multiple actors of the same type. A message which is send to the pool will be forwarded to an actor inside the pool which has the lowest workload at the time the message is processed.\n\nYou can create an actor pool by invoking the method below on the class of your choice. An actor instance will be created and passed into the configuration block for further initialization:\n\n```objc\nTBActorPool *pool = [Worker poolWithSize:10 configuration:^(NSObject *actor) {\n    Worker *worker = (Worker *)actor;\n    worker.name = @\"worker\";\n    worker.Id = @(123);\n}];\n```\n\nYou can send messages to the pool:\n\n```objc\n[pool.sync setName:@\"worker\"];\n[pool.async doSomething];\n```\n\nSame goes for subscriptions:\n\n```objc\n[pool subscribe:@\"notificationToWorkers\" selector:@selector(handler:)];\n[pool unsubscribe:@\"notificationToWorkers\"];\n```\n\nThe handler will be executed by an available actor in the pool.\n\n#### Broadcasts\n\nTo send an asynchronous message to all actors inside the pool:\n\n```objc\n[pool.broadcast ping];\n```\n\n### Promises\n\nPromise support using [PromiseKit](http://promisekit.org) is available via the subspec `Promises`:\n\n```ruby\ntarget 'MyApp', :exclusive =\u003e true do\n  pod 'ActorKit/Promises'\nend\n```\n\n```objc\n#import \u003cActorKit/Promises.h\u003e\n```\n\nSend a asynchronous message and receive a promise back:\n\n```objc\n((AnyPromise *)[worker.promise returnSomethingBlocking])\n.then(^(id result) {\n    \n    // ...\n});\n```\n\n### Supervision and Linking of Actors\n\nSupervision and Linking is available via the subspec `Supervision`:\n\n```ruby\ntarget 'MyApp', :exclusive =\u003e true do\n  pod 'ActorKit/Supervision'\nend\n```\n\n```objc\n#import \u003cActorKit/Supervision.h\u003e\n```\n\n#### Supervised Actors\n\nYou can create supervised actors by passing an id and a creation block to a supervision pool:\n\n```objc\nTBActorSupervisionPool *actors = [TBActorSupervisionPool new];\n\n[actors superviseWithId:@\"master\" creationBlock:^NSObject * {\n    Worker *worker = Worker.new;\n    worker.name = @\"master\";\n    worker.Id = @(123);\n    return worker;\n}];\n```\n\nThe creation block will be called whenever the actor needs to be (re)created.\n\n#### Accessing Actors Inside the Supervision Pool\n\nAccess the supervised actor by its id on the supervision pool:\n\n```objc\n[actors[@\"master\"].sync doSomething];\n```\n\n#### Unsupervising Actors\n\nTo remove an actor from a supervision pool:\n\n```objc\n[actors unsuperviseActorWithId:@\"master\"];\n```\n\n#### Linking Actors\n\nLinks establish parent-child relationships between actors. Linked actors will be supervised depending on each other. If the parent actor crashes the child actor will be re-created as well. Whenever an actor is removed from the supervision pool its linked actors are removed as well.\n\n```objc\n[actors linkActor:@\"child\" toParentActor:@\"master\"];\n```\n\nTo remove a link:\n\n```objc\n[actors unlinkActor:@\"child\" fromParentActor:@\"master\"];\n```\n\n#### Recovering from Crashes\n\nWhenever a supervised actor crashes it is re-created and will resume processing pending messages from its mailbox.\n\n**Special behavior for pools:**\n\n- when the pool actor itself crashes the whole pool is recreated completely and the content of all mailboxes will be processed by the new pool instance\n- when an actor inside the pool crashes only that instance is recreated and its mailbox content will be processed by its successor\n\nYou can also communicate a crash manually by calling `crashWithError:`:\n\n```objc\n@implementation Worker\n\n- (void)doSomething\n{\n    NSError *error = nil;\n    [self _doSomethingInternal:\u0026error];\n    if (error) {\n        [self crashWithError:error];\n    }\n}\n\n@end\n```\n**Attention:** Cocoa is not a framework which employs exceptions as a legitimate means to communicate errors. There are a lot of layers which prevent exceptions to bubble up the stack until they can be handled by the supervisor (GCD etc.). So be prepared for exceptions which still can crash the application.\n\n**Warning:** Scheduling your own operations on the actor queue directly is strongly discouraged since the supervision can not guarantee that this operations can be executed properly by the new actor instance.\n\n## Architecture\n\nThis framework seeks for a very simple implementation of actors. It basically consists of a category which lazily adds an `NSOperationQueue` to the `NSObject` which should work as an actor. Messages sent to the actor are forwarded by an `NSProxy` using `NSInvocation` and `NSOperation` objects. These classes represent mailboxes, threads and messages etc.\n\n## Example Project\n\nTo run the example project, clone the repo, and run `pod install` from the `./ActorKit` directory first.\n\n## Useful Theory on Actors\n\n- https://en.wikipedia.org/wiki/Actor_model\n\n## Author\n\nJulian Krumow, julian.krumow@bogusmachine.com\n\n## License\n\nActorKit is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjkrumow%2Factorkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjkrumow%2Factorkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjkrumow%2Factorkit/lists"}