-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added: Example test for simple promise
- Loading branch information
Showing
2 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
package loop_test | ||
|
||
import ( | ||
"fmt" | ||
"github.com/donutloop/toolkit/loop" | ||
"time" | ||
"fmt" | ||
) | ||
|
||
func ExampleLoop() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package promise_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/donutloop/toolkit/promise" | ||
) | ||
|
||
func ExamplePromise() { | ||
|
||
done, errc := promise.Do(context.Background(), func(ctx context.Context) error { | ||
fmt.Println("do things") | ||
return nil | ||
}) | ||
|
||
select { | ||
case <-done: | ||
case err := <-errc: | ||
fmt.Println(fmt.Sprintf("error: %v", err)) | ||
} | ||
|
||
// Output: do things | ||
} |