[Proposal] async getter/setter #3227
Replies: 10 comments
-
Similarly, setter are used in special situations to modify the database, and the function returns if the modification is successful |
Beta Was this translation helpful? Give feedback.
-
What would be the syntax to invoke the setter? |
Beta Was this translation helpful? Give feedback.
-
Also, how does either the getter work without returning an instance of In order for waiting to be asynchronous, the member being called must return before there is a B instance to hand back. It must return an object that is capable of subscribing a delegate to be called back as soon as there is an instance of |
Beta Was this translation helpful? Give feedback.
-
good question, I have no idea |
Beta Was this translation helpful? Give feedback.
-
may new grammar |
Beta Was this translation helpful? Give feedback.
-
Fallible and/or time sensitive operations should not be hidden behind properties. The setter should set local state and a separate method used to initiate the asynchronous operation back to the database. https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/property That aside, there's technically nothing in the CLR that would forbid asynchronous properties. A property declared as type |
Beta Was this translation helpful? Give feedback.
-
The database object model is like this: public class A : Model {
public Guid? ModbId { get; set; }
public B Modb { async get; async set; }
public string name { get; set; }
};
public class B : Model {
public Guid? ModaId { get; set; }
public Task<A> Modb { get; }
public async Task set_a (A a) {}
public int age { get; set; }
}; Semantically, the |
Beta Was this translation helpful? Give feedback.
-
I don't really see an issue with having |
Beta Was this translation helpful? Give feedback.
-
The case this feature would be great to use is binding in WPF. For example you have such XAML:
And you want to perform some async operations in setter of
Not the best C# code, but i have no idea how to do this in a better way without async setters |
Beta Was this translation helpful? Give feedback.
-
@zetroot The better way that I settled on after years of trying other things is https://github.com/Techsola/AmbientTasks. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
example:
Applicable scenarios: for example, in the database ORM domain, the one-to-one relationship between the two object models of AB exists. When accessing B through the variable of model A (that is, the getter), the database is asynchronously inquired, and other background HTTP requests developed based on this ORM framework are not blocked.
call async get/set:
Beta Was this translation helpful? Give feedback.
All reactions