-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
unique_lock & shared_lock #16
Labels
C++11
C++14
enhancement
New feature or request
help wanted
Extra attention is needed
question
Further information is requested
Projects
Comments
I'm planning to adapt the 1st way. You've an another idea or opposite opinion, then please tell me. |
I decided to adapt both of them all. Type restriction would be enhanced like such below: export class SharedLock<Mutex extends IMutex>
{
public constructor(mutex: Mutex);
public lock(closure: Closure): Promise<void>;
public try_lock(closure: Closure): Promise<boolean>;
public try_lock_for: "try_lock_shared_for" extends keyof Mutex
? (ms: number, closure: Closure) => Promise<boolean>
: undefined;
public try_lock_until: "try_lock_shared_until" extends keyof Mutex
? (at: Date, closure: Closure) => Promise<boolean>
: undefined;
}
export namespace SharedLock
{
export function lock<Mutex extends Pick<_ISharedLockable, "lock_shared"|"unlock_shared">>
(mutex: Mutex, closure: Closure): Promise<void>;
export function try_lock<Mutex extends Pick<_ISharedLockable, "try_lock_shared"|"unlock_shared">>
(mutex: Mutex, closure: Closure): Promise<boolean>;
export function try_lock_for<Mutex extends Pick<_ISharedTimedLockable, "try_lock_shared_for"|"unlock_shared">>
(mutex: Mutex, ms: number, closure: Closure): Promise<boolean>;
export function try_lock_until<Mutex extends Pick<_ISharedTimedLockable, "try_lock_shared_until"|"unlock_shared">>
(mutex: Mutex, at: Date, closure: Closure): Promise<boolean>;
}
export import shared_lock = SharedLock;
interface IMutex
{
lock_shared(): Promise<void>;
unlock_sharedO(): Promise<void>;
try_lock_shared(): Promise<boolean>;
try_lock_shared_for?(ms: number): Promise<boolean>;
try_lock_shared_until?(at: Date): Promise<boolean>;
}
type Closure = () => void | Promise<void>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
C++11
C++14
enhancement
New feature or request
help wanted
Extra attention is needed
question
Further information is requested
In C++ STL,
unique_lock
&shared_lock
ensures safety locks using destruction pattern. However, unlike C++, JS does not support thedestructor
, thus TSTL should design alternative solutions for those safety locks.My answer is to using closure function for the safety lock. However, I haven't determined the detailed solution yet. I've two candidate solutions. Which one would be better? I'm looking forward to your ideas and opinions.
1. Global Functions in Namespace
2. Class providing Lambda Methods
The text was updated successfully, but these errors were encountered: