Skip to content

Commit

Permalink
PR Update
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinClabaut committed Apr 26, 2022
1 parent add3bb1 commit be2c4dc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ ch := lo.Async(func() lo.Tuple2[int, error] {
### Async{0->1}

Executes a function in a goroutine and returns the result in a channel.
For function without return, the channel will be closed once the function finishes.
For function without return, the channel will be set once the function finishes.

```go
ch := lo.Async0(func() { time.Sleep(10 * time.Second) })
Expand Down
6 changes: 3 additions & 3 deletions concurrency.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ func Async[T any](f func() T) chan T {
return ch
}

// Async0 executes a function in a goroutine and returns a channel closed after execution.
// Async0 executes a function in a goroutine and returns a channel set once the function finishes.
func Async0(f func()) chan struct{} {
ch := make(chan struct{})
go func() {
f()
close(ch)
ch <- struct{}{}
}()
return ch
}

// Async1 executes a function in a goroutine and returns the result in a channel.
// Async1 is an alias to Async.
func Async1[A any](f func() A) chan A {
return Async(f)
}

0 comments on commit be2c4dc

Please sign in to comment.