Allow toService to be bound to async service #1441
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
toService method:
Was using get method that throws exception when it would return promise. It caused prevented resolution of service using
getAsync
method.getAsync
could not be used instead because it always return promise even when resolution returns simple value (async
keyword on function have that effect)Removal of
async
keyword would changegetAsync
result - it would work for clients usingawait
because one can await simple value but it would break for clients callingthen
/catch
because simple values does not have them.New function
getMaybeAsync
was introduced instead to Container interface returning promise when resolved to promise and simple value when resolved to simple value.If introduction of new interface method is not desired then I see another way to approach problem - by passing if resolution is sync/async through Context.
Related Issue
#1409
Motivation and Context
toService binding were using Container.get method internally so it was throwing exception when the binding target was promise even if the resolution was also asynchroneous (getAsync)
How Has This Been Tested?
Added new automated test case.
All old test cases are passing.
Types of changes
Checklist:
I will update changelog/documentation if general shape of PR is acceptable.