Skip to content

Commit d562060

Browse files
committed
NoAsyncRunSynchronouslyInLibrary: updated docs
To address feedback.
1 parent baecfb8 commit d562060

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

docs/content/how-tos/rules/FL0087.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ hide_menu: true
66

77
# NoAsyncRunSynchronouslyInLibrary (FL0087)
88

9-
*Introduced in `0.26.7`*
9+
*Introduced in `0.26.8`*
1010

1111
## Cause
1212

@@ -19,12 +19,39 @@ The rule assumes the code is in the library if none of the following is true:
1919

2020
## Rationale
2121

22-
Using `Async.RunSynchronously` outside of scripts and tests can lead to program becoming non-responsive.
22+
Using `Async.RunSynchronously` outside of scripts, tests, and console projects can lead to program becoming non-responsive.
2323

2424
## How To Fix
2525

2626
Remove `Async.RunSynchronously` and wrap the code that uses `async` computations in `async` computation, using `let!`, `use!`, `match!`, or `return!` keyword to get the result.
2727

28+
Example:
29+
30+
```fsharp
31+
let someFunc someParam =
32+
let foo =
33+
asyncOtherFunc someParam
34+
|> Async.RunSynchronously
35+
processFoo foo
36+
```
37+
38+
The function can be modified to be asynchronous. In that case it might be better to prefix its name with Async:
39+
40+
```fsharp
41+
let asyncSomeFunc someParam = async {
42+
let! foo = asyncOtherFunc someParam
43+
return processFoo foo
44+
}
45+
```
46+
47+
In case the method/function is public, a nice C#-friendly overload that returns `Task<'T>` could be provided, suffixed with Async, that just calls the previous method with `Async.StartAsTask`:
48+
49+
```fsharp
50+
let someFuncAsync someParam =
51+
asyncSomeFunc someParam
52+
|> Async.StartAsTask
53+
```
54+
2855
## Rule Settings
2956

3057
{

0 commit comments

Comments
 (0)