-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5728d6
commit 15b2e36
Showing
6 changed files
with
108 additions
and
109 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,3 +1,3 @@ | ||
module github.com/studiolambda/yotei | ||
|
||
go 1.22.0 | ||
go 1.23.0 |
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
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,59 @@ | ||
package yotei | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
type Tasker interface { | ||
Handler | ||
Duration() time.Duration | ||
Weight() uint64 | ||
Lock() | ||
Unlock() | ||
IsLocked() bool | ||
IsConcurrent() bool | ||
} | ||
|
||
// A list of actionable tasks | ||
type Tasks []Tasker | ||
|
||
// Determines that the task can take unlimited duration. | ||
var DurationUnlimited time.Duration = 0 | ||
|
||
// Weight returns the sum of all he | ||
// weights of all the tasks in the list. | ||
func (tasks Tasks) Weight() uint64 { | ||
total := uint64(0) | ||
|
||
for _, task := range tasks { | ||
total += task.Weight() | ||
} | ||
|
||
return total | ||
} | ||
|
||
// Unlocked returns the tasks that are unlocked | ||
func (tasks Tasks) Unlocked() Tasks { | ||
unlocked := make(Tasks, 0) | ||
|
||
for _, task := range tasks { | ||
if !task.IsLocked() { | ||
unlocked = append(unlocked, task) | ||
} | ||
} | ||
|
||
return unlocked | ||
} | ||
|
||
// Locked returns the tasks that are locked | ||
func (tasks Tasks) Locked() Tasks { | ||
locked := make(Tasks, 0) | ||
|
||
for _, task := range tasks { | ||
if task.IsLocked() { | ||
locked = append(locked, task) | ||
} | ||
} | ||
|
||
return locked | ||
} |