Skip to content

Commit 6aae637

Browse files
authored
Merge pull request #6 from GGXXLL/master
feat: rename newPool to NewPool
2 parents a25bafd + 3ebf92c commit 6aae637

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

dependency.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
// Providers provide a *pool.Pool to the core.
1010
func Providers(options ...ProviderOptionFunc) di.Deps {
11-
return di.Deps{newPool(options...)}
11+
return di.Deps{NewPool(options...)}
1212
}
1313

1414
// ProviderOptionFunc is the functional option to Providers.

pool.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// The package pool is a generic solution for async job dispatching from web
1+
// Package pool is a generic solution for async job dispatching from web
22
// server. While Go natively supports async jobs by using the keyword "go", but
33
// this may lead to several unwanted consequences. Suppose we have a typical http handler:
44
//
@@ -58,7 +58,8 @@ type job struct {
5858
function func(ctx context.Context)
5959
}
6060

61-
func newPool(options ...ProviderOptionFunc) func(contract.Dispatcher) *Pool {
61+
// NewPool returned func(contract.Dispatcher) *Pool
62+
func NewPool(options ...ProviderOptionFunc) func(contract.Dispatcher) *Pool {
6263
return func(dispatcher contract.Dispatcher) *Pool {
6364
pool := Pool{
6465
ch: make(chan job),

pool_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestPool_Go(t *testing.T) {
1313
t.Parallel()
1414
ctx, cancel := context.WithCancel(context.Background())
1515
dispatcher := events.SyncDispatcher{}
16-
p := newPool(WithConcurrency(1), WithShutdownEvents())(&dispatcher)
16+
p := NewPool(WithConcurrency(1), WithShutdownEvents())(&dispatcher)
1717
go p.Go(context.Background(), func(asyncContext context.Context) {
1818
cancel()
1919
})
@@ -26,7 +26,7 @@ func TestPool_Timeout(t *testing.T) {
2626
defer cancel()
2727

2828
dispatcher := events.SyncDispatcher{}
29-
p := newPool(WithTimeout(time.Second), WithConcurrency(1), WithShutdownEvents())(&dispatcher)
29+
p := NewPool(WithTimeout(time.Second), WithConcurrency(1), WithShutdownEvents())(&dispatcher)
3030
go p.Go(context.Background(), func(asyncContext context.Context) {
3131
select {
3232
case <-asyncContext.Done():
@@ -47,7 +47,7 @@ func TestPool_contextValue(t *testing.T) {
4747
defer cancel()
4848

4949
dispatcher := events.SyncDispatcher{}
50-
p := newPool(WithConcurrency(1), WithShutdownEvents())(&dispatcher)
50+
p := NewPool(WithConcurrency(1), WithShutdownEvents())(&dispatcher)
5151
key := struct{}{}
5252
requestContext := context.WithValue(context.Background(), key, "foo")
5353
go p.Go(requestContext, func(asyncContext context.Context) {
@@ -66,7 +66,7 @@ func TestPool_ProvideRunGroup(t *testing.T) {
6666
t.Parallel()
6767
t.Run("run group should exit if no shutdown event is specified", func(t *testing.T) {
6868
dispatcher := events.SyncDispatcher{}
69-
p := newPool(WithConcurrency(1), WithShutdownEvents())(&dispatcher)
69+
p := NewPool(WithConcurrency(1), WithShutdownEvents())(&dispatcher)
7070
var group run.Group
7171
group.Add(func() error { return nil }, func(err error) {})
7272
p.ProvideRunGroup(&group)
@@ -77,7 +77,7 @@ func TestPool_ProvideRunGroup(t *testing.T) {
7777
dispatcher := events.SyncDispatcher{}
7878
var fooEvent = "fooEvent"
7979
var barEvent = "barEvent"
80-
p := newPool(WithConcurrency(1), WithShutdownEvents(fooEvent, barEvent))(&dispatcher)
80+
p := NewPool(WithConcurrency(1), WithShutdownEvents(fooEvent, barEvent))(&dispatcher)
8181
var group run.Group
8282
group.Add(func() error { return nil }, func(err error) {})
8383
p.ProvideRunGroup(&group)

0 commit comments

Comments
 (0)