Skip to content

Commit

Permalink
Fdb: add protected ctor to FdbFuture that alllows passing custom Task…
Browse files Browse the repository at this point in the history
…CreationOptions

- FdbFutureTask can be constructed with custom options, like RunContinuationsAsynchronously
  • Loading branch information
KrzysFR committed Dec 1, 2024
1 parent 7a939ca commit a3c6132
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions FoundationDB.Client/Native/FdbFuture.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -115,10 +115,16 @@ public static Task<TResult[]> CreateTaskFromHandleArray<TState, TResult>(FutureH
return new FdbFutureArray<TState, TResult>(handles, state, selector, ct).Task;
}

/// <summary>Create a generic <see cref="FdbFuture{T}"/> that has a lifetime tied to a cancellation token</summary>
/// <typeparam name="T"></typeparam>
/// <param name="ct">Token used to cancel the future from the outside</param>
/// <param name="options">Optional creation options for the underlying <see cref="Task{T}"/></param>
/// <returns>Future that will automatically be cancelled if the linked token is cancelled.</returns>
/// <remarks>This is mostly used to create Watches or futures that behave similarly to watches.</remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static FdbFuture<T> Create<T>(CancellationToken ct)
public static FdbFuture<T> Create<T>(CancellationToken ct, TaskCreationOptions options = TaskCreationOptions.None)
{
return new FdbFutureTask<T>(ct);
return new FdbFutureTask<T>(ct, options);
}

}
Expand All @@ -143,6 +149,10 @@ public abstract class FdbFuture<TResult> : TaskCompletionSource<TResult>, IDispo

#endregion

protected FdbFuture() { }

protected FdbFuture(TaskCreationOptions options) : base(options) { }

#region State Management...

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down Expand Up @@ -402,10 +412,12 @@ public void Dispose()

}

/// <summary>Generic <see cref="FdbFuture{TResult}"/> that will behave like a <see cref="Task{TResult}"/></summary>
/// <remarks>Can be used to replicate the behaviors of Watches or other async database operations</remarks>
public sealed class FdbFutureTask<TResult> : FdbFuture<TResult>
{

public FdbFutureTask(CancellationToken ct)
public FdbFutureTask(CancellationToken ct, TaskCreationOptions options) : base(options)
{
if (ct.CanBeCanceled)
{
Expand Down

0 comments on commit a3c6132

Please sign in to comment.