-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b992dd4
commit e1d94b8
Showing
15 changed files
with
466 additions
and
411 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace Temporalio.Bridge | ||
{ | ||
/// <summary> | ||
/// Core wrapper for a user-defined custom slot supplier. | ||
/// </summary> | ||
internal class CustomSlotSupplier : NativeInvokeableClass<Interop.CustomSlotSupplierCallbacks> | ||
{ | ||
private readonly Temporalio.Worker.Tuning.ICustomSlotSupplier userSupplier; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CustomSlotSupplier" /> class. | ||
/// </summary> | ||
/// <param name="userSupplier">User's slot supplier implementation'.</param> | ||
internal unsafe CustomSlotSupplier(Temporalio.Worker.Tuning.ICustomSlotSupplier userSupplier) | ||
{ | ||
this.userSupplier = userSupplier; | ||
|
||
var interopCallbacks = new Interop.CustomSlotSupplierCallbacks | ||
{ | ||
reserve = FunctionPointer<Interop.CustomReserveSlotCallback>(Reserve), | ||
try_reserve = FunctionPointer<Interop.CustomTryReserveSlotCallback>(TryReserve), | ||
mark_used = FunctionPointer<Interop.CustomMarkSlotUsedCallback>(MarkUsed), | ||
release = FunctionPointer<Interop.CustomReleaseSlotCallback>(Release), | ||
}; | ||
|
||
PinCallbackHolder(interopCallbacks); | ||
} | ||
|
||
private void Reserve(Interop.SlotReserveCtx ctx) | ||
{ | ||
// TODO: Need to call callback with result that will put it in a channel to await in Rust | ||
var reserveTask = Task.Run(() => userSupplier.ReserveSlotAsync(new(ctx))); | ||
} | ||
|
||
private void TryReserve(Interop.SlotReserveCtx ctx) | ||
{ | ||
userSupplier.TryReserveSlot(new(ctx)); | ||
} | ||
|
||
private void MarkUsed(Interop.SlotMarkUsedCtx ctx) | ||
{ | ||
userSupplier.MarkSlotUsed(new(ctx)); | ||
} | ||
|
||
private void Release(Interop.SlotReleaseCtx ctx) | ||
{ | ||
userSupplier.ReleaseSlot(new(ctx)); | ||
} | ||
} | ||
} |
Oops, something went wrong.