Skip to content

Commit

Permalink
chore: add todo
Browse files Browse the repository at this point in the history
  • Loading branch information
justlorain committed Jan 23, 2024
1 parent 9571af4 commit c0bcfa0
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
16 changes: 16 additions & 0 deletions consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package violin

import "math"

const (
DefaultViolinMaxWorkerNum = math.MaxInt32
DefaultViolinWorkerIdleTimeout = 0
)

const (
_ uint32 = iota
statusInitialized
statusPlaying
statusCleaning
statusShutdown
)
2 changes: 2 additions & 0 deletions helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"time"
)

// TODO: merge violin.go with helper.go

func (v *Violin) submit(wait bool, task func()) {
if task == nil {
return
Expand Down
4 changes: 2 additions & 2 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ type options struct {

var defaultOptions = options{
minWorkers: 0,
maxWorkers: 5,
workerIdleTimeout: 3 * time.Second,
maxWorkers: DefaultViolinMaxWorkerNum,
workerIdleTimeout: DefaultViolinWorkerIdleTimeout,
}

func newOptions(opts ...Option) *options {
Expand Down
27 changes: 27 additions & 0 deletions pool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package violin

// TODO: refer to ants

var defaultViolin *Violin

func init() {
defaultViolin = New(WithMaxWorkers(DefaultViolinMaxWorkerNum), WithWorkerIdleTimeout(DefaultViolinWorkerIdleTimeout))
}

func Submit(task func()) error {
//return defaultViolin.Submit(task)
return nil
}

func SubmitWait(task func()) error {
//return defaultViolin.SubmitWait(task)
return nil
}

func WorkerNum() uint32 {
return defaultViolin.WorkerNum()
}

func MaxWorkerNum() int {
return defaultViolin.MaxWorkerNum()
}
9 changes: 1 addition & 8 deletions violin.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ type Violin struct {
shutdownC chan struct{}
}

const (
_ uint32 = iota
statusInitialized
statusPlaying
statusCleaning
statusShutdown
)

// New VIOLIN worker pool
// TODO: improve performance
func New(opts ...Option) *Violin {
Expand All @@ -70,6 +62,7 @@ func New(opts ...Option) *Violin {
}

// Submit a task to the worker pool
// TODO: error handling
func (v *Violin) Submit(task func()) {
v.submit(false, task)
}
Expand Down

0 comments on commit c0bcfa0

Please sign in to comment.