Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/d-exclaimation/desolate
A scalable concurrency toolkit for Swift 5.5+
https://github.com/d-exclaimation/desolate
actor-model async-await concurrency reactive-streams streaming swift
Last synced: about 2 months ago
JSON representation
A scalable concurrency toolkit for Swift 5.5+
- Host: GitHub
- URL: https://github.com/d-exclaimation/desolate
- Owner: d-exclaimation
- License: apache-2.0
- Created: 2021-10-31T17:09:32.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-06-13T14:18:39.000Z (over 2 years ago)
- Last Synced: 2024-05-13T14:51:30.564Z (8 months ago)
- Topics: actor-model, async-await, concurrency, reactive-streams, streaming, swift
- Language: Swift
- Homepage: https://swift-desolate.netlify.app/documentation/desolate
- Size: 415 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Desolate
A scalable concurrency toolkit for Swift 5.5+
> **WARNING**: Deprecated and no longer maintained
[Desolate](https://github.com/d-exclaimation/desolate) is a toolkit for Swift 5.5+ Actors and Concurrency capabilities. The library provide structures to model Swift Actors using [Desolate](https://github.com/d-exclaimation/desolate) that maintains its isolation while allowing both synchronous and asynchronous code to interface with the actors.
### Documentation
- [Documentation](https://swift-desolate.netlify.app/documentation/desolate)
### Usages/Examples
Simple concurrent safe store showing the maintained isolation even when actor is given messages from a main synchronous task
```swift
import Desolateenum StoreEvent: CustomStringConvertible {
case update(key: String, item: String)
case store(item: String, ref: Receiver)
case add(item: String)
case get(key: String, ref: Receiver)
case getAll(ref: Receiver<[String]>)
case delete(key: String)var description: String {
switch self {
case .update(key: let key, item: let item):
return "PUT/PATCH: \(key) -> \"\(item)\""
case .store(item: let item, ref: _):
return "POST: \"\(item)\""
case .add(item: let item):
return "POST: \"\(item)\""
case .get(key: let key, ref: _):
return "GET: \(key)"
case .getAll(ref: _):
return "GET: *"
case .delete(key: let key):
return "DELETE: \(key)"
}
}
}actor Store: AbstractDesolate, NonStop {
private var storage: [String: (String, Date)] = [:]public func onMessage(msg: StoreEvent) async -> Signal {
print("Received: \(msg)")switch msg {
case .update(let key, let item):
storage[key] = (item, Date())case .store(let item, let ref):
let key = UUID().uuidString
storage[key] = (item, Date())
ref.tell(with: key)case .get(let key, let ref):
ref.tell(with: storage[key]?.0)case .getAll(let ref):
ref.tell(with: storage.values.sorted { $0.1 <= $1.1 } .map{ $0.0 })case .delete(let key):
storage.removeValue(forKey: key)
}return same
}
}let desolate = Desolate(of: Store())
desolate.tell(with: .add(item: "Hello")) // Passing message to Actor while maintaining actor-isolation
```### Feedback
If you have any feedback, feel free to reach out through the issues tab or through my
Twitter [@d_exclaimation](https://twitter.com/d_exclaimation).