-
-
Notifications
You must be signed in to change notification settings - Fork 39
Full compatibility with -strict-concurrency=complete
#125
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
501e6e1
eebb46c
aeb7356
cdc40d5
e791f5c
423abf5
9f22e7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // swift-tools-version:5.4 | ||
| // swift-tools-version:5.6 | ||
| import PackageDescription | ||
|
|
||
| let package = Package( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,33 @@ | ||
| import NIOConcurrencyHelpers | ||
| import NIO | ||
|
|
||
| public final class DefaultLeafCache: SynchronousLeafCache { | ||
| /// `@unchecked Sendable` because uses locks to guarantee Sendability. | ||
| public final class DefaultLeafCache: SynchronousLeafCache, @unchecked Sendable { | ||
| // MARK: - Public - `LeafCache` Protocol Conformance | ||
|
|
||
|
|
||
| var __isEnabled = true | ||
| /// Global setting for enabling or disabling the cache | ||
| public var isEnabled: Bool = true | ||
| public var _isEnabled: Bool { | ||
| get { | ||
| self.lock.withLock { | ||
| self.__isEnabled | ||
| } | ||
| } | ||
| set(newValue) { | ||
| self.lock.withLock { | ||
| self.__isEnabled = newValue | ||
| } | ||
| } | ||
| } | ||
| /// Global setting for enabling or disabling the cache | ||
| public var isEnabled: Bool { | ||
| get { | ||
| self._isEnabled | ||
| } | ||
| set(newValue) { | ||
| self._isEnabled = newValue | ||
| } | ||
| } | ||
| /// Current count of cached documents | ||
|
Comment on lines
7
to
31
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why two layers of indirection?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i assume compiler will take care of that anyway... two levels to not use |
||
| public var count: Int { self.lock.withLock { cache.count } } | ||
|
|
||
|
|
@@ -73,7 +95,7 @@ public final class DefaultLeafCache: SynchronousLeafCache { | |
|
|
||
| // MARK: - Internal Only | ||
|
|
||
| internal let lock: Lock | ||
| internal let lock: NIOLock | ||
| internal var cache: [String: LeafAST] | ||
|
|
||
| /// Blocking file load behavior | ||
MahdiBM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ import NIO | |
| /// | ||
| /// Additional instances of LeafRenderer can then be created using these shared modules to allow | ||
| /// concurrent rendering, potentially with unique per-instance scoped data via `userInfo`. | ||
| public final class LeafRenderer { | ||
| public final class LeafRenderer: Sendable { | ||
| // MARK: - Public Only | ||
|
|
||
| /// An initialized `LeafConfiguration` specificying default directory and tagIndicator | ||
|
|
@@ -25,9 +25,12 @@ public final class LeafRenderer { | |
| public let sources: LeafSources | ||
| /// The NIO `EventLoop` on which this instance of `LeafRenderer` will operate | ||
| public let eventLoop: EventLoop | ||
| let _userInfo: SendableBox<[AnyHashable: Any]> | ||
|
||
| /// Any custom instance data to use (eg, in Vapor, the `Application` and/or `Request` data) | ||
| public let userInfo: [AnyHashable: Any] | ||
|
|
||
| public var userInfo: [AnyHashable: Any] { | ||
| _userInfo.value | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this crash on access by users on another |
||
| } | ||
|
|
||
| /// Initial configuration of LeafRenderer. | ||
| public init( | ||
| configuration: LeafConfiguration, | ||
|
|
@@ -42,7 +45,7 @@ public final class LeafRenderer { | |
| self.cache = cache | ||
| self.sources = sources | ||
| self.eventLoop = eventLoop | ||
| self.userInfo = userInfo | ||
| self._userInfo = .init(userInfo) | ||
| } | ||
|
|
||
| /// The public interface to `LeafRenderer` | ||
|
|
@@ -164,6 +167,7 @@ public final class LeafRenderer { | |
|
|
||
| let fetchRequests = ast.unresolvedRefs.map { self.fetch(template: $0, chain: chain) } | ||
|
|
||
| let constantChain = chain | ||
| let results = EventLoopFuture.whenAllComplete(fetchRequests, on: self.eventLoop) | ||
| return results.flatMap { results in | ||
| let results = results | ||
|
|
@@ -182,7 +186,7 @@ public final class LeafRenderer { | |
| // Check new AST's unresolved refs to see if extension introduced new refs | ||
| if !new.unresolvedRefs.subtracting(ast.unresolvedRefs).isEmpty { | ||
| // AST has new references - try to resolve again recursively | ||
| return self.resolve(ast: new, chain: chain) | ||
| return self.resolve(ast: new, chain: constantChain) | ||
| } else { | ||
| // Cache extended AST & return - AST is either flat or unresolvable | ||
| return self.cache.insert(new, on: self.eventLoop, replace: true) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.