You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor: Convert TaskManagerActor to class and simplify SwiftUI integration (#13)
## Summary
- Converted TaskManagerActor from actor to final class with manual
synchronization for better performance
- Renamed TaskManagerActor to TaskManager for simplicity
- Renamed SwiftUI property wrapper from TaskManager to LocalTask to
avoid naming conflicts
- Removed LocalTaskWrapper, exposing TaskManager directly from the
property wrapper
## Changes
### Core Refactoring
- **TaskNode**: Converted from class to struct with
OSAllocatedUnfairLock for thread-safe state management
- **TaskManager** (formerly TaskManagerActor): Converted from actor to
class with Sendable conformance
- Uses OSAllocatedUnfairLock for manual synchronization
- Removed actor overhead for better performance
- Removed batch methods as they're no longer needed
### File Organization
- Extracted TaskNode into separate file (`TaskNode.swift`)
- Extracted AutoReleaseContinuationBox into separate file
(`AutoReleaseContinuationBox.swift`)
### SwiftUI Integration
- Renamed @taskmanager property wrapper to @localtask
- Removed LocalTaskWrapper intermediate layer
- Direct exposure of TaskManager instance from property wrapper
- Simplified API surface
## Test Results
All tests passing ✅
## Breaking Changes
- `TaskManagerActor` renamed to `TaskManager`
- SwiftUI property wrapper renamed from `@TaskManager` to `@LocalTask`
- Batch methods removed
🤖 Generated with [Claude Code](https://claude.ai/code)
---------
Co-authored-by: Claude <[email protected]>
let products =tryawait api.fetchProducts(category: category)
287
+
await MainActor.run {
288
+
self.products= products
292
289
}
293
290
}
294
291
}
@@ -297,17 +294,17 @@ class ProductListViewModel {
297
294
298
295
## 📚 API Reference
299
296
300
-
### TaskManagerActor
297
+
### TaskManager
301
298
302
-
The main actor that manages task execution.
299
+
The main class that manages task execution with thread-safe operations.
303
300
304
301
#### Methods
305
302
306
303
-`task(label:key:mode:priority:operation:)` - Submit a task for execution
307
304
-`taskDetached(label:key:mode:priority:operation:)` - Submit a detached task
308
-
-`batch(_:)` - Execute multiple operations in a batch
309
305
-`setIsRunning(_:)` - Control task execution state
310
306
-`isRunning(for:)` - Check if a task is running for a given key
307
+
-`cancel(key:)` - Cancel tasks for a specific key
311
308
-`cancelAll()` - Cancel all managed tasks
312
309
313
310
### TaskKey
@@ -329,13 +326,13 @@ Identifies and groups related tasks.
329
326
330
327
### SwiftUI Components
331
328
332
-
#### @TaskManager Property Wrapper
329
+
#### @LocalTask Property Wrapper
333
330
334
-
Provides TaskManager functionality in SwiftUI views with automatic lifecycle management.
331
+
Provides TaskManager functionality in SwiftUI views with automatic lifecycle management. The property wrapper directly exposes a `TaskManager` instance that is automatically cleaned up when the view is deallocated.
335
332
336
-
#### TaskManagerActorWrapper
333
+
#### Extension Methods
337
334
338
-
SwiftUI-friendly wrapper with `isRunning` binding support.
335
+
TaskManager includes a SwiftUI-specific extension method `taskWithBinding` that provides `isRunning` binding support for tracking task execution state.
0 commit comments