-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new methods to routineGroup struct and test case
- Add a new method `Run` to the `routineGroup` struct in `thread.go` - Add a new method `Wait` to the `routineGroup` struct in `thread.go` - Add a new test case for the `Run` method in `thread_test.go` Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
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
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 +1,28 @@ | ||
package graceful | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestRun(t *testing.T) { | ||
g := newRoutineGroup() | ||
|
||
// Define a flag to check if the function was executed | ||
var executed bool | ||
|
||
// Define the function to be executed | ||
fn := func() { | ||
executed = true | ||
} | ||
|
||
// Run the function in a goroutine | ||
g.Run(fn) | ||
|
||
// Wait for the goroutine to finish | ||
g.Wait() | ||
|
||
// Check if the function was executed | ||
if !executed { | ||
t.Error("Function was not executed") | ||
} | ||
} |