Repository navigation
Conversation
| // HandleLostToken can be expensive to obtain on some providers, so we don't touch the underlying | ||
| // handles until we're asked for the token, and we only ever do so once. We track that with a | ||
| // separate flag rather than a null check because a null source is itself a valid memoized result | ||
| // (it means no underlying handle has a cancelable token), which we must not recompute on each read. |
There was a problem hiding this comment.
If I understand correctly, this is optimizing away this code on the getter when HandleLost is not supported on all tokens:
var cancellableTokens = handles
.Select(h => h.HandleLostToken)
.Where(t => t.CanBeCanceled)
.ToArray();
Is that correct? Feels unnecessary to me as it only optimizes the case where (a) none of the types in the chain have handle lost and yet (b) HandleLost is being accessed with some frequency. Am I missing something?
There was a problem hiding this comment.
Yes, that's correct. Indeed a narrow case, so I won't die on that hill. It was just case of "hmm...that can legitemately be null even when acquired".
|
Thanks for sharing @gliljas . Reading through, my reaction is we end up with a lot of API surface area for fairly narrow functionality. Today, with composites our API supports 1 provider + N names but in theory the underlying My inclination is to keep things simple and just add an API like this: This small change would expose everything needed to build targeted decorators in userland. It wouldn't stop us from adding them to the library in the future, but it feels like a no-regrets move. As far as the in-process use-case, I feel like there's a bit more nuance around how you might want this to work. For example:
This makes me think that that scenario might be best supported by dedicated functionality directly focused on tiered synchronization rather than generic functionality which has multiple purposes. |
I believe you may be correct. For my use case, I really needed it to be wrapped as a provider, but that could be easily built on top of extension methods.
Fair point
Interesting idea!
Yes! I've thought about that too. It would be somewhat similar to using two ConcurrencyRateLimiters inside a ChainedRateLimiter, which is a bit more complex with queues and stuff, but still. |
I started this branch like two years ago, but other things got in the way. The idea is to enable chaining of two or more synchronization providers, so that locks and semaphores must be acquired by all included providers. They fail or succeed together. Since I started, the CompositeDistributedSynchronizationHandle was added, and I could remove a lot of my code and use that instead.
So, what's the use case? We used it (a separate wrapper that I ended up with) when doing a rolling migration from one Azure lock account to another, and we're using it again now to migrate from Azure to Redis. All seamless, since we can ensure that locks are acquired in both places during the migration.
The second use case I see is that it together with the In Process provider (#291 ) enables us to not consume resources on the shared state if the lock was already acquired by the same process. Simply add the in process provider as the first in the chain.