Swiftpack.co - Package - backslash-f/worker

swift-version swift-package-manager build-status license

Worker

Execute async code in the main or background threads. Easily switch between them.

Usage

import Worker

// Execute code in a background thread.
Worker.doBackgroundWork {
	print("Background thread work...")
}

// Execute code in the main thread.
Worker.doMainThreadWork {
	print("Main thread work...")
}

// Execute code in a background thread and update the UI afterwards.
Worker.doBackgroundWork {
	print("Something expensive...")

    Worker.doMainThreadWork {
    	print("Update the UI.")
    }
}

Worker's background threads use QoS .userInitiated to execute code asynchronously with a higher priority.
From Apple:

User-initiated tasks are second only to user-interactive tasks in their priority on the system. Assign this class to tasks that provide immediate results for something the user is doing, or that would prevent the user from using your app. For example, you might use this quality-of-service class to load the content of an email that you want to display to the user.

Integration

Xcode

Use Xcode's built-in support for SPM.

Package.swift

In your Package.swift, add Worker as a dependency:

dependencies: [
  .package(url: "https://github.com/backslash-f/worker", from: "1.0.0")
],

Associate the dependency with your target:

targets: [
  .target(name: "App", dependencies: ["Worker"])
]

Run: swift build

Github

link
Stars: 0

Dependencies

Used By

Total: 0

Releases

First Release - 2020-02-22 17:30:55