<#CQ2QFLNFL|dotnet> <#CJ909TL6P|typescript> I'm tr...
# dotnet
t
#dotnet #typescript I'm trying to convert this to C#, but I can't make sense of it. Anyone?
Copy code
readonly result: Promise<T>;

    resolveResult!: (v: any) => void;
    rejectResult!: (e: Error) => void;

    constructor(program: () => Promise<T>) {
        this.program = program;
        this.result = new Promise<any>((resolve, reject) => {
            this.resolveResult = resolve;
            this.rejectResult = reject;
        });
        this.running = false;
    }
First off, what do these translate to?
Copy code
resolveResult!: (v: any) => void;
    rejectResult!: (e: Error) => void;
f
I think this should be similar to defining
Func<object, void> resolveResult
I’m guessing you’re looking at this from the automation API perspective though? In which case, I assume you’ll have something that results in a
Task
and then needing to handle the success/failure of that task. /cc @lemon-agent-27707
👍 2
t
Very close, it's
Action<object>
.
f
Ah, sorry 🙂 Been a while since I’ve done much C#
t
Next question:
resolveResult
&
rejectResult
(seen here) are just declarations, right? Where are they initialized?
No worries. I understood what you meant.
l
that chunk you linked does initialize
resolveResult
and
rejectResult
(the promise constructor runs the executor immediately https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise#Parameters) The goal of linking these properties from the
LanguageServer.result
property was to make it easy for other downstream consumers to interact with language server. In practice we don't really use the exposed promise and handle the lifetime a little more manually. I would not feel constrained by this for the dotnet implementation, it's really just to make callbacks easier to manage in javascript.
t
I’m not sure about the context but TaskCompletionSource sounds the closest to the resolve/reject pair?
I guess I should understand the context before giving advice 😂