Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeferredOutput<T> #385

Merged
merged 1 commit into from
Nov 21, 2024
Merged

DeferredOutput<T> #385

merged 1 commit into from
Nov 21, 2024

Conversation

Frassle
Copy link
Member

@Frassle Frassle commented Nov 13, 2024

Adds DeferredOutput<T> that allows the creation of an Output<T> that can later be resolved to the final result of a different Output<T>.

This can be used to solve partial circular reference problems. For example given two components that create multiple resources and return some results from that, you would normally have to have all the inputs for one component available to call it and then afterwards call the other component. With an DeferredOutput<T> you can instead set up a circular reference:

var ocs = new DeferredOutput<int>()
var (resultA1, resultA2) = MakeComponentA(ocs.Output);
var resultB = MakeComponentB(resultA1);
ocs.Resolve(resultB);

As long as MakeComponentA can resolve its A1 result without needing the incoming output resolved then the above will work.

Note that it's possible to deadlock the program with this feature. If resultA1 above can't resolve until the input is resolved, and resultB can't resolve till its input is resolved then both will end up stuck waiting for the other. Users can already deadlock their programs with other dotnet constructs (for example doing a similar thing with TaskCompletionSource<T>).

Copy link
Contributor

@Zaid-Ajaj Zaid-Ajaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to start using in C# program-gen, unless there are things we are uncertain about yet?

@Frassle
Copy link
Member Author

Frassle commented Nov 15, 2024

Yeh let me fill in docs then we can probably merge this.

@Frassle Frassle marked this pull request as ready for review November 15, 2024 08:41
@Frassle Frassle requested a review from a team as a code owner November 15, 2024 08:41
@justinvp
Copy link
Member

Are we settled on the API design and naming for this? What's it going to look like in the other SDKs?

@Zaid-Ajaj
Copy link
Contributor

Are we settled on the API design and naming for this? What's it going to look like in the other SDKs?

Will be discussing next week but leaning towards a unified name DeferredOutput<T> for all the languages

@Frassle Frassle force-pushed the fraser/ocs branch 2 times, most recently from a3c94e8 to bda6049 Compare November 19, 2024 08:28
@Frassle Frassle changed the title OutputCompletionSource DeferredOutput<T> Nov 19, 2024
@Frassle Frassle force-pushed the fraser/ocs branch 4 times, most recently from d0941a6 to b647f31 Compare November 19, 2024 21:17
@Frassle Frassle added this pull request to the merge queue Nov 21, 2024
Merged via the queue into main with commit 2e83237 Nov 21, 2024
17 checks passed
@Frassle Frassle deleted the fraser/ocs branch November 21, 2024 10:24
@julienp julienp mentioned this pull request Nov 21, 2024
@pulumi-bot
Copy link

This PR has been shipped in release v3.69.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants