-
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.
Merge pull request #26 from donutloop/feat/example_tests
Feat/example tests
- Loading branch information
Showing
4 changed files
with
84 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package retry_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/donutloop/toolkit/retry" | ||
) | ||
|
||
func ExampleRetrier() { | ||
r := retry.NewRetrier() | ||
err := r.Retry(context.Background(), func() (bool, error) { | ||
fmt.Println("fire request") | ||
return true, nil | ||
}) | ||
|
||
if err != nil { | ||
fmt.Println(fmt.Sprintf("error: (%v)", err)) | ||
} | ||
|
||
// Output: fire request | ||
} |
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,25 @@ | ||
package schedule_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/donutloop/toolkit/schedule" | ||
) | ||
|
||
func ExampleFIFOScheduler() { | ||
|
||
s := schedule.NewFIFOScheduler() | ||
defer s.Stop() | ||
|
||
job := func(ctx context.Context) { | ||
fmt.Println("create db entry") | ||
} | ||
|
||
if err := s.Schedule(job); err != nil { | ||
fmt.Println(fmt.Sprintf("error: (%v)", err)) | ||
} | ||
|
||
s.WaitFinish(1) | ||
|
||
// Output: create db entry | ||
} |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package singleton_test | ||
|
||
import ( | ||
"fmt" | ||
"github.com/donutloop/toolkit/singleton" | ||
) | ||
|
||
func ExampleSingleton() { | ||
|
||
type config struct { | ||
Addr string | ||
Port int | ||
} | ||
|
||
configSingleton := singleton.NewSingleton(func() (interface{}, error) { | ||
return &config{Addr: "localhost", Port: 80}, nil | ||
}) | ||
|
||
configFunc := func() (*config, error) { | ||
s, err := configSingleton.Get() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return s.(*config), nil | ||
} | ||
|
||
configFunc() | ||
|
||
c, err := configFunc() | ||
if err != nil { | ||
fmt.Println(fmt.Sprintf("error: (%v)", err)) | ||
} | ||
|
||
fmt.Println(fmt.Sprintf("%#v", c)) | ||
// Output: &singleton_test.config{Addr:"localhost", Port:80} | ||
} |