-
-
Notifications
You must be signed in to change notification settings - Fork 8
feat: add async/await support to MemoryAdapter for Swift 6 concurrency #53
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
hsluoyz
merged 8 commits into
casbin:master
from
wendylabsinc:feat/async-await-migration
Oct 16, 2025
Merged
feat: add async/await support to MemoryAdapter for Swift 6 concurrency #53
hsluoyz
merged 8 commits into
casbin:master
from
wendylabsinc:feat/async-await-migration
Oct 16, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Update Package.swift with minimum platform requirements (macOS 10.15, iOS 13, etc.) - Add async/await overloads for all 9 MemoryAdapter methods: - loadPolicy(m:) - loadFilteredPolicy(m:f:) - savePolicy(m:) - clearPolicy() - addPolicy(sec:ptype:rule:) - addPolicies(sec:ptype:rules:) - removePolicy(sec:ptype:rule:) - removePolicies(sec:ptype:rules:) - removeFilteredPolicy(sec:ptype:fieldIndex:fieldValues:) Original EventLoopFuture-based methods remain for backward compatibility. Async/await versions provide cleaner, more maintainable concurrency code. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Add 7 test cases covering all async/await methods: - ✅ async addPolicy and loadPolicy - ✅ async addPolicies and savePolicy - ✅ async removePolicy - ⏭️ async removePolicies (skipped - pre-existing bug in implementation) - ✅ async clearPolicy - ✅ async removeFilteredPolicy - ✅ async loadFilteredPolicy Note: removePolicies test disabled due to pre-existing bug where logic checks `if policy.contains(rule)` instead of `if !policy.contains(rule)`. This bug exists in both EventLoopFuture and async/await implementations. 6/7 tests pass, verifying async/await methods work identically to EventLoopFuture versions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…emoryAdapter load/save with model
- Make removePolicies atomic: return true only if all rules exist; otherwise do not remove any
- Fix inverted existence check and remove early return
- Mirror semantics in DefaultModel.removePolicies
- MemoryAdapter.savePolicy: write explicit section ('p'/'g') instead of iterating ptype characters
- MemoryAdapter.loadPolicy/loadFilteredPolicy: drop [sec, ptype] headers; append only rule fields
- Fix loadFilteredPolicy indexing to match dropped headers
- Tests: re-enable async removePolicies test; update expectations to no-ptype rules
…cAwait.swift for clarity
…sions; gate with @available; no behavior changes
|
🎉 This PR is included in version 1.15.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
zamderax
added a commit
to wendylabsinc/SwiftCasbin
that referenced
this pull request
Oct 16, 2025
- Add Config+AsyncAwait.swift with async/await overloads for static factory methods - Add DefaultModel+AsyncAwait.swift with async/await overloads for static factory methods - Both follow the same pattern as PR casbin#53 with @available annotations and continuation-based bridging - Methods bridge existing EventLoopFuture-based APIs to async/await Note: Tests have a pre-existing hang issue on this branch unrelated to these changes. The code compiles successfully and follows the established async/await patterns. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Add async/await overloads for MemoryAdapter, FileAdapter, and Enforcer while keeping the original EventLoopFuture-based APIs intact. Methods are split into
+AsyncAwait.swiftextensions and availability-gated to match Package.swift platforms.Changes
MemoryAdapter
Sources/Casbin/Adapter/MemoryAdapter+AsyncAwait.swift.removePoliciesto be atomic (all-or-nothing). Mirrored inDefaultModel.removePolicies.savePolicyto use explicit section headers ("p"/"g").loadPolicy/loadFilteredPolicynow append only rule fields (noptype) and fixed filter indexing.FileAdapter
Sources/Casbin/Adapter/FileAdapter+AsyncAwait.swiftthat bridge existing futures via continuations.@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *).Enforcer
Sources/Casbin/Enforcer+AsyncAwait.swiftfor common operations:loadPolicy,loadFilteredPolicy,savePolicy,clearPolicy,setModel,setAdapterenforce(_:)addPolicy,addPolicies,removePolicy,removePolicies,removeFilteredPolicy, and grouping counterparts)Tests
removePoliciestest and updated expectations (model policies don’t includeptype).swift testpasses locally (XCTest + Swift Testing).Rationale
@availablemaintains backward compatibility with the current platforms defined in Package.swift.