Skip to content

Commit

Permalink
Deprecate ActorIsolated. (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrandonw authored Jun 23, 2024
1 parent d7eac73 commit 675c56c
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
{
"originHash" : "109102968f72b508a09c97740fede846eb2bb9291019254db091bfbfbc0e073a",
"pins" : [
{
"identity" : "swift-docc-plugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-plugin",
"state" : {
"revision" : "3303b164430d9a7055ba484c8ead67a52f7b74f6",
"revision" : "26ac5758409154cc448d7ab82389c520fa8a8247",
"version" : "1.3.0"
}
},
{
"identity" : "swift-docc-symbolkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-symbolkit",
"state" : {
"revision" : "b45d1f2ed151d057b54504d653e0da5552844e34",
"version" : "1.0.0"
}
}
],
"version" : 2
"version" : 3
}
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Reliably testable Swift concurrency.

* [Motivation](#motivation)
* [`ActorIsolated` and `LockIsolated`](#actorisolated-and-lockisolated)
* [`LockIsolated`](#lockisolated)
* [Streams](#streams)
* [Tasks](#tasks)
* [Serial execution](#serial-execution)
Expand All @@ -34,19 +34,16 @@ You can watch all of the episodes [here](https://www.pointfree.co/collections/co
This library comes with a number of tools that make working with Swift concurrency easier and more
testable.

* [`ActorIsolated` and `LockIsolated`](#actorisolated-and-lockisolated)
* [`LockIsolated`](#lockisolated)
* [Streams](#streams)
* [Tasks](#tasks)
* [`UncheckedSendable`](#uncheckedsendable)
* [Serial execution](#serial-execution)

### `ActorIsolated` and `LockIsolated`
### LockIsolated`

The `ActorIsolated` and `LockIsolated` types help wrap other values in an isolated context.
`ActorIsolated` wraps the value in an actor so that the only way to access and mutate the value is
through an async/await interface. `LockIsolated` wraps the value in a class with a lock, which
allows you to read and write the value with a synchronous interface. You should prefer to use
`ActorIsolated` when you have access to an asynchronous context.
The `LockIsolated` type helps wrap other values in an isolated context. It wraps the value in a
class with a lock, which allows you to read and write the value with a synchronous interface.

### Streams

Expand Down
1 change: 1 addition & 0 deletions Sources/ConcurrencyExtras/ActorIsolated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
/// ```
///
/// To synchronously isolate a value, see ``LockIsolated``.
@available(*, deprecated, message: "Use 'LockIsolated' instead.")
public final actor ActorIsolated<Value> {
/// The actor-isolated value.
public var value: Value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ Useful, testable Swift concurrency.
This library comes with a number of tools that make working with Swift concurrency easier and more
testable.

### ActorIsolated and LockIsolated
### LockIsolated

The ``ActorIsolated`` and ``LockIsolated`` types help wrap other values in an isolated context.
`ActorIsolated` wraps the value in an actor so that the only way to access and mutate the value is
through an async/await interface. ``LockIsolated`` wraps the value in a class with a lock, which
allows you to read and write the value with a synchronous interface. You should prefer to use
`ActorIsolated` when you have access to an asynchronous context.
The `LockIsolated` type helps wrap other values in an isolated context. It wraps the value in a
class with a lock, which allows you to read and write the value with a synchronous interface.

### Streams

Expand Down Expand Up @@ -238,13 +235,12 @@ need to make weaker assertions due to non-determinism, but can still assert on s

### Data races

- ``ActorIsolated``
- ``LockIsolated``

### Serial execution

- <doc:ReliablyTestingAsync>
- ``withMainSerialExecutor(operation:)-79jpc``
- ``withMainSerialExecutor(operation:)-5wq73``

### Preconcurrency

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Deprecations

Review unsupported reducer APIs and their replacements.

## Overview

Avoid using deprecated APIs in your app. Select a method to see the replacement that you should use
instead.

## Topics

### Case path deprecations

- ``ActorIsolated``
4 changes: 2 additions & 2 deletions Sources/ConcurrencyExtras/LockIsolated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Foundation

/// A generic wrapper for isolating a mutable value with a lock.
///
/// To asynchronously isolate a value on an actor, see ``ActorIsolated``. If you trust the
/// sendability of the underlying value, consider using ``UncheckedSendable``, instead.
/// If you trust the sendability of the underlying value, consider using ``UncheckedSendable``,
/// instead.
@dynamicMemberLookup
public final class LockIsolated<Value>: @unchecked Sendable {
private var _value: Value
Expand Down
3 changes: 1 addition & 2 deletions Sources/ConcurrencyExtras/UncheckedSendable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
/// > that the type is safe to use from multiple threads, and the compiler cannot help you find
/// > potential race conditions in your code.
///
/// To synchronously isolate a value with a lock, see ``LockIsolated``. To asynchronously isolated a
/// value on an actor, see ``ActorIsolated``.
/// To synchronously isolate a value with a lock, see ``LockIsolated``.
#if swift(>=5.10)
@available(iOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")@available(
macOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead."
Expand Down
1 change: 1 addition & 0 deletions Tests/ConcurrencyExtrasTests/ActorIsolatedTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ConcurrencyExtras
import XCTest

@available(*, deprecated)
final class ActorIsolatedTests: XCTestCase {
func testAsyncWithValue() async {
let numbers = ActorIsolated<Set<Int>>([])
Expand Down
1 change: 1 addition & 0 deletions Tests/ConcurrencyExtrasTests/MainSerialExecutorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
XCTAssertEqual(Array(1...1000), xs.value)
}

@available(*, deprecated)
func testSerializedExecution_WithActor() async {
let xs = ActorIsolated<[Int]>([])
await withMainSerialExecutor {
Expand Down

0 comments on commit 675c56c

Please sign in to comment.