Allow obtaining serializable tokens that represent JoinableTasks#1162
Allow obtaining serializable tokens that represent JoinableTasks#1162AArnott merged 1 commit intomicrosoft:mainfrom
Conversation
lifengl
left a comment
There was a problem hiding this comment.
those changes look good to me.
|
One potential thing to consider is that we don't need inject the JTF context into the chain, if the current JTF context has no UI thread. I am not sure this is doable in the JTF side, or you want to leave it to StreamJsonRpc (i guess it is tricky to know that state in StreamJsonRpc), that will allow us to prevent this cost on services which has JTF just to run code in the compatible way, (and I guess most services do not have UI thread), so it could limit the context string to include a single or very few contextId in the real world even the call chain passes through several layers? |
|
Yes, I'll look into making |
…skContext` objects and processes
To enable RPC calls (e.g. JSON-RPC -- not COM calls), we add two new APIs:
string? JoinableTaskContext.Capture()- returns a token that represents theJoinableTaskthat is currently running, and its tokenized parents.JoinableTask JoinableTaskFactory.RunAsync(Func<Task>, string?, JoinableTaskCreationOptions)- applies a token previously obtained from anyCapture()call (even from another process) so that anyJoinableTaskcontext that matches thisJoinableTaskContextobject will be applied as a parent to the newJoinableTask.Together, this allows RPC infrastructure to utilize
JoinableTaskFactoryto mitigate deadlocks due to requirements on the same UI thread that would otherwise be undetectable as dependencies due to how RPC runs its own queues, and may weave in and out of the process.Prior to merging:
nullfromCapture()when theJoinableTaskContextis in 'no main thread' mode.