From a3c6132afb8cc373cfa77d66efe5dfe5e966b193 Mon Sep 17 00:00:00 2001 From: Christophe Chevalier Date: Sun, 1 Dec 2024 20:28:03 +0100 Subject: [PATCH] Fdb: add protected ctor to FdbFuture that alllows passing custom TaskCreationOptions - FdbFutureTask can be constructed with custom options, like RunContinuationsAsynchronously --- FoundationDB.Client/Native/FdbFuture.cs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/FoundationDB.Client/Native/FdbFuture.cs b/FoundationDB.Client/Native/FdbFuture.cs index 8ff1b7b80..a057f1b2b 100644 --- a/FoundationDB.Client/Native/FdbFuture.cs +++ b/FoundationDB.Client/Native/FdbFuture.cs @@ -1,4 +1,4 @@ -#region Copyright (c) 2023-2024 SnowBank SAS, (c) 2005-2023 Doxense SAS +#region Copyright (c) 2023-2024 SnowBank SAS, (c) 2005-2023 Doxense SAS // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -115,10 +115,16 @@ public static Task CreateTaskFromHandleArray(FutureH return new FdbFutureArray(handles, state, selector, ct).Task; } + /// Create a generic that has a lifetime tied to a cancellation token + /// + /// Token used to cancel the future from the outside + /// Optional creation options for the underlying + /// Future that will automatically be cancelled if the linked token is cancelled. + /// This is mostly used to create Watches or futures that behave similarly to watches. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static FdbFuture Create(CancellationToken ct) + public static FdbFuture Create(CancellationToken ct, TaskCreationOptions options = TaskCreationOptions.None) { - return new FdbFutureTask(ct); + return new FdbFutureTask(ct, options); } } @@ -143,6 +149,10 @@ public abstract class FdbFuture : TaskCompletionSource, IDispo #endregion + protected FdbFuture() { } + + protected FdbFuture(TaskCreationOptions options) : base(options) { } + #region State Management... [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -402,10 +412,12 @@ public void Dispose() } + /// Generic that will behave like a + /// Can be used to replicate the behaviors of Watches or other async database operations public sealed class FdbFutureTask : FdbFuture { - public FdbFutureTask(CancellationToken ct) + public FdbFutureTask(CancellationToken ct, TaskCreationOptions options) : base(options) { if (ct.CanBeCanceled) {