mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-23 21:06:22 +08:00
feat(core): new worker workspace engine (#9257)
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// Mutex.swift
|
||||
// App
|
||||
//
|
||||
// Created by EYHN on 2025/1/11.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
final class Mutex<Wrapped>: @unchecked Sendable {
|
||||
private let lock = NSLock.init()
|
||||
private var wrapped: Wrapped
|
||||
|
||||
init(_ wrapped: Wrapped) {
|
||||
self.wrapped = wrapped
|
||||
}
|
||||
|
||||
func withLock<R>(_ body: @Sendable (inout Wrapped) throws -> R) rethrows -> R {
|
||||
self.lock.lock()
|
||||
defer { self.lock.unlock() }
|
||||
return try body(&wrapped)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user