https://pulumi.com logo
#dotnet
Title
# dotnet
t

tall-needle-56640

12/04/2020, 5:52 PM
#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

faint-table-42725

12/04/2020, 6:10 PM
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

tall-needle-56640

12/04/2020, 6:30 PM
Very close, it's
Action<object>
.
f

faint-table-42725

12/04/2020, 6:36 PM
Ah, sorry 🙂 Been a while since I’ve done much C#
t

tall-needle-56640

12/04/2020, 6:37 PM
Next question:
resolveResult
&
rejectResult
(seen here) are just declarations, right? Where are they initialized?
No worries. I understood what you meant.
l

lemon-agent-27707

12/04/2020, 7:11 PM
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

tall-librarian-49374

12/04/2020, 7:39 PM
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 😂