Skip to content

Commit

Permalink
Terminate intersected lifetime if rd task result is not bindable
Browse files Browse the repository at this point in the history
  • Loading branch information
Iliya-usov committed Oct 19, 2023
1 parent 221bb5a commit 1c4c9c7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,14 @@ class RdCall<TReq, TRes>(internal val requestSzr: ISerializer<TReq> = Polymorphi

val taskId = proto.identity.next(RdId.Null)
val bindLifetime = bindLifetime
val taskLifetime = lifetime.intersect(bindLifetime)

val task = CallSiteWiredRdTask(taskLifetime, this, taskId, scheduler ?: proto.scheduler)
taskLifetime.executeIfAlive {
val intersectedDef = lifetime.defineIntersection(bindLifetime)
val task = CallSiteWiredRdTask(intersectedDef.lifetime, this, taskId, scheduler ?: proto.scheduler)
task.result.advise(intersectedDef.lifetime) {
if (it !is RdTaskResult.Success || !it.value.isBindable()) {
intersectedDef.terminate()
}
}
intersectedDef.lifetime.executeIfAlive {
proto.wire.send(rdid) { buffer ->
logSend.trace { "call `$location`::($rdid) send${sync.condstr {" SYNC"}} request '$taskId' : ${request.printToString()} " }
taskId.write(buffer)
Expand Down
13 changes: 9 additions & 4 deletions rd-net/RdFramework/Tasks/RdCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,15 @@ private IRdTask<TRes> StartInternal(Lifetime requestLifetime, TReq request, ISch

var taskId = proto.Identities.Next(RdId.Nil);

var taskLifetime = Lifetime.Intersect(requestLifetime, myBindLifetime);
var task = new WiredRdTask<TReq, TRes>.CallSite(taskLifetime, this, taskId, scheduler ?? proto.Scheduler);

using var cookie = taskLifetime.UsingExecuteIfAlive();
var intersectedDef = Lifetime.DefineIntersection(requestLifetime, myBindLifetime);
var task = new WiredRdTask<TReq,TRes>.CallSite(intersectedDef.Lifetime, this, taskId, scheduler ?? proto.Scheduler);
task.Result.Advise(intersectedDef.Lifetime, result =>
{
if (result.Status != RdTaskStatus.Success || !result.Result.IsBindable())
intersectedDef.Terminate();
});

using var cookie = intersectedDef.UsingExecuteIfAlive();
if (cookie.Succeed)
{
proto.Wire.Send(RdId, (writer) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a RdGen v1.11.
// This code was generated by a RdGen v1.12.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a RdGen v1.11.
// This code was generated by a RdGen v1.12.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand Down

0 comments on commit 1c4c9c7

Please sign in to comment.