mirror of
https://github.com/minio/minio.git
synced 2025-01-26 14:13:16 -05:00
Make priority queue lambda function return error over a channel
This commit is contained in:
parent
38a6ce36e5
commit
0533abf6a8
@ -30,24 +30,44 @@ type MySuite struct{}
|
||||
|
||||
var _ = Suite(&MySuite{})
|
||||
|
||||
func helloTask1() error {
|
||||
fmt.Println("Hello task1")
|
||||
return nil
|
||||
func helloTask1() <-chan error {
|
||||
errCh := make(chan error)
|
||||
go func() {
|
||||
defer close(errCh)
|
||||
println("Hello task1")
|
||||
errCh <- nil
|
||||
}()
|
||||
return errCh
|
||||
}
|
||||
|
||||
func helloTask2() error {
|
||||
fmt.Println("Hello task2")
|
||||
return nil
|
||||
func helloTask2() <-chan error {
|
||||
errCh := make(chan error)
|
||||
go func() {
|
||||
defer close(errCh)
|
||||
println("Hello task2")
|
||||
errCh <- nil
|
||||
}()
|
||||
return errCh
|
||||
}
|
||||
|
||||
func newJob1() error {
|
||||
fmt.Println("New Job1")
|
||||
return nil
|
||||
func newJob1() <-chan error {
|
||||
errCh := make(chan error)
|
||||
go func() {
|
||||
defer close(errCh)
|
||||
println("New Job1")
|
||||
errCh <- nil
|
||||
}()
|
||||
return errCh
|
||||
}
|
||||
|
||||
func newJob2() error {
|
||||
fmt.Println("New Job2")
|
||||
return nil
|
||||
func newJob2() <-chan error {
|
||||
errCh := make(chan error)
|
||||
go func() {
|
||||
defer close(errCh)
|
||||
println("New Job2")
|
||||
errCh <- nil
|
||||
}()
|
||||
return errCh
|
||||
}
|
||||
|
||||
func (s *MySuite) TestPQ(c *C) {
|
||||
|
@ -18,7 +18,7 @@ package pq
|
||||
|
||||
// Task container for any generic tasks
|
||||
type Task struct {
|
||||
job func() error
|
||||
job func() <-chan error
|
||||
priority int
|
||||
}
|
||||
|
||||
@ -34,5 +34,5 @@ func (t Task) UpdatePriority(p int) {
|
||||
|
||||
// Execute execute current task
|
||||
func (t Task) Execute() error {
|
||||
return t.job()
|
||||
return <-t.job()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user