Skip to content

The Hollywood library provides a simple API for tracking the state of asynchronous Swift Structured Concurrency workflows.

License

Notifications You must be signed in to change notification settings

briancoyner/hollywood

Repository files navigation

Hollywood

Header

The Hollywood library provides developers a simple API for tracking the state of an asynchronous Swift Structured Concurrency workflow, with optional progress reporting.

There are two core APIs: ContextualActor and WorkflowAction.

A ContextualActor asynchronously executes and publishes the result of a WorkflowAction that produces a type T. A ContextualActor transitions between ContextualActor/States, i.e. ready, busy, success, failure. The current state is available by reading/ observing the state property. This makes it super easy to tie in with SwiftUI.

A WorkflowAction is a simple command (think GoF command) implementation that asynchronously executes to produce a value T. A good way to think about this protocol is that it forces you to give a discoverable name (via a concrete type) to a top-level asynchronous function. For a large code base, with multiple developers contributing code, this enables discoverability, improves future maintenance, and just generally helps organize top-level reusable functions.

GeneralDiagram

WorkflowActions are composable. This means it's super easy to stitch together WorkflowActions into a complex asynchronous execution graph. To further help with discoverability, maintenance, and progress reporting, you can lean on the CompositeWorkflowActionandUnitOfWork`.

Examples

Workflows that require tracking state changes:

  • Fetching anything from a web service (JSON, images, etc.)
  • Uploading anything to a web service.
  • Performing SQLite database reads and writes.
  • Long running computations.

Workflows that benefit from progress reporting:

  • Downloading large files over a network.
  • Decompressing/ compressing large files.
  • Importing a large amount of data into a local persistent store (SQLite, Core Data, etc.)
  • Long running computations.

Hollywood Demos

The Hollywood-Demos repo contains several working examples (including the example above). Additional examples will be added in the future.

  • GitHub OAuth sign-in workflow.
  • iTunes Music search (with album artwork download example).
  • Numerous progress reporting examples.

Unit Tests

There are numerous unit tests showing how to use Hollywood, as well as showing techniques for unit testing asynchronous workflows.

Requirements

  • Swift 5.10+
  • iOS 17+
  • macOS 14+

Adding Hollywood as a Dependency

To use the Hollywood library in a SwiftPM project simply add the following to your Package.swift file:

.package(url: "https://github.com/briancoyner/hollywood.git", branch: "main"),
.target(name: "<target>", dependencies: [
     .product(name: "Hollywood", package: "hollywood")
]),

Finally, add import Hollywood as needed to your source files.

What's Next?

  • More demos are in the works, so you should watch and/ star the Hollywood-Demos repo.
  • Introduce HollywoodTestKit to make it easier for you to write asynchronous unit tests.
  • Additional DocC documentation (there's a decent start, but it's far from great).

Credits

Hollywood is written and maintained by Brian Coyner.

License

Hollywood and HollywoodUI is released under the MIT License. See LICENSE for details.

About

The Hollywood library provides a simple API for tracking the state of asynchronous Swift Structured Concurrency workflows.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages