Some method still synchronous.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
1 year ago
There is still some synchronous method. Maybe there is a ticket already open for this. Something like below.

https://github.com/nopSolutions/nopCommerce/blob/8017076517dcdd6309c8426555080b9288c1844c/src/Libraries/Nop.Services/Discounts/DiscountService.cs#L312

Do not know will it cause any issue for calling a synchronous method from the asynchronous method.
1 year ago
/// <summary>
/// Get preferred discount (with maximum discount value)
/// </summary>
/// <param name="discounts">A list of discounts to check</param>
/// <param name="amount">Amount (initial value)</param>
/// <param name="discountAmount">Discount amount</param>
/// <returns>Preferred discount</returns>
public virtual List<Discount> GetPreferredDiscount(IList<Discount> discounts,
            decimal amount, out decimal discountAmount)

This routine does not need to be Synchronous because all it does is some calculations, record manipulation and the routines it calls i.e. GetDiscountAmount(...) are also Synchronous.
i.e. it does not call any async routines and everything runs in realtime

In fact if you changed it to be an async routine then the compiler will provide the warning
warning CS1998: This async method lacks 'await' operators and will run synchronously.
1 year ago
Yidna wrote:
/// <summary>
/// Get preferred discount (with maximum discount value)
/// </summary>
/// <param name="discounts">A list of discounts to check</param>
/// <param name="amount">Amount (initial value)</param>
/// <param name="discountAmount">Discount amount</param>
/// <returns>Preferred discount</returns>
public virtual List<Discount> GetPreferredDiscount(IList<Discount> discounts,
            decimal amount, out decimal discountAmount)

This routine does not need to be Synchronous because all it does is some calculations, record manipulation and the routines it calls i.e. GetDiscountAmount(...) are also Synchronous.
i.e. it does not call any async routines and everything runs in realtime

In fact if you changed it to be an async routine then the compiler will provide the warning
warning CS1998: This async method lacks 'await' operators and will run synchronously.


Without making the inner method async we can not use await operator. so for the inner method, we can write something like await Task.FromResult(whateverthevalue); and then call it from the main method by await operator.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.