Skip to content

Create Task API -> 0.7.0 #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 8, 2025
Merged

Create Task API -> 0.7.0 #51

merged 8 commits into from
Apr 8, 2025

Conversation

dfed
Copy link
Owner

@dfed dfed commented Apr 2, 2025

Addresses #50

This PR represents a breaking change of the API. In this PR, we:

  • Replaced the .enqueue (and similar) API on both FIFOQueue and ActorQueue with a Task-based API. Now operations can be enqueued on these queues with Task(on: queue). By creating a Task, we now allow consumers to cancel pending tasks.
  • Removed the MainActorQueue entirely, and replaced it with Task(on: MainActor.queue)

The good news is that migration is quite straightforward.

  • Replace queue.enqueue { … } with Task(on: queue) { … }
  • Replace await queue.enqueueAndWait { … } with await Task(on: queue) { … }.value
  • Replace try await queue.enqueueAndWait { … } with try await Task(on: queue) { … }.value
  • Replace try await queue.enqueueAndWait { … } with await Task(on: queue) { … }.value
  • Replace queue.enqueue(on: someActor) { someActor in … } with Task(on: queue, isolatedTo: someActor) { someActor in … }
  • Replace MainActorQueue.shared.enqueue { … } with Task(on: MainActor.queue) { … }

These changes enable consumers to store and cancel enqueued tasks.

@dfed dfed self-assigned this Apr 2, 2025
@dfed dfed linked an issue Apr 2, 2025 that may be closed by this pull request
@dfed dfed force-pushed the dfed--task-api branch 3 times, most recently from d261c62 to c5297ef Compare April 2, 2025 07:41
Copy link

codecov bot commented Apr 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (2985121) to head (43041c1).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##              main       #51   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           11        10    -1     
  Lines         1060      1119   +59     
=========================================
+ Hits          1060      1119   +59     
Files with missing lines Coverage Δ
Sources/AsyncQueue/ActorQueue.swift 100.00% <100.00%> (ø)
Sources/AsyncQueue/FIFOQueue.swift 100.00% <100.00%> (ø)
Sources/AsyncQueue/Utilities/Delivery.swift 100.00% <100.00%> (ø)
Sources/AsyncQueue/Utilities/Semaphore.swift 100.00% <100.00%> (ø)
Tests/AsyncQueueTests/ActorQueueTests.swift 100.00% <100.00%> (ø)
Tests/AsyncQueueTests/FIFOQueueTests.swift 100.00% <100.00%> (ø)
Tests/AsyncQueueTests/SemaphoreTests.swift 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dfed dfed force-pushed the dfed--task-api branch 7 times, most recently from 5e2c2f4 to 0df8eac Compare April 2, 2025 08:21
@dfed dfed marked this pull request as ready for review April 2, 2025 08:25
@dfed dfed force-pushed the dfed--task-api branch from 0df8eac to 61cc272 Compare April 2, 2025 08:32
@dfed dfed requested a review from Copilot April 7, 2025 07:09
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 11 changed files in this pull request and generated no comments.

Files not reviewed (9)
  • Sources/AsyncQueue/ActorQueue.swift: Language not supported
  • Sources/AsyncQueue/FIFOQueue.swift: Language not supported
  • Sources/AsyncQueue/MainActorQueue.swift: Language not supported
  • Sources/AsyncQueue/Utilities/Delivery.swift: Language not supported
  • Sources/AsyncQueue/Utilities/Semaphore.swift: Language not supported
  • Tests/AsyncQueueTests/ActorQueueTests.swift: Language not supported
  • Tests/AsyncQueueTests/FIFOQueueTests.swift: Language not supported
  • Tests/AsyncQueueTests/MainActorQueueTests.swift: Language not supported
  • Tests/AsyncQueueTests/SemaphoreTests.swift: Language not supported
Comments suppressed due to low confidence (1)

README.md:104

  • The migration instructions specify using the 'isolatedTo' parameter when enqueuing tasks on an actor; consider changing this to 'await Task(on: queue, isolatedTo: myself) { myself in' to fully adhere to the new API.
await Task(on: queue) { myself in

@dfed dfed merged commit f1ff3cd into main Apr 8, 2025
8 checks passed
@dfed dfed deleted the dfed--task-api branch April 8, 2025 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cancellable interface for FIFOQueue
1 participant