-
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.
feat: add job and task job for MaaControllerId, MaaResourceId and Maa…
…TaskId
- Loading branch information
Showing
10 changed files
with
1,131 additions
and
80 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
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,50 @@ | ||
package maa | ||
|
||
import "time" | ||
|
||
type Job struct { | ||
id int64 | ||
statusFunc func(id int64) Status | ||
} | ||
|
||
func NewJob(id int64, statusFunc func(id int64) Status) Job { | ||
return Job{ | ||
id: id, | ||
statusFunc: statusFunc, | ||
} | ||
} | ||
|
||
func (job Job) Status() Status { | ||
return job.statusFunc(job.id) | ||
} | ||
|
||
func (job Job) Invalid() bool { | ||
return job.Status().Invalid() | ||
} | ||
|
||
func (job Job) Pending() bool { | ||
return job.Status().Pending() | ||
} | ||
|
||
func (job Job) Running() bool { | ||
return job.Status().Running() | ||
} | ||
|
||
func (job Job) Success() bool { | ||
return job.Status().Success() | ||
} | ||
|
||
func (job Job) Failure() bool { | ||
return job.Status().Failure() | ||
} | ||
|
||
func (job Job) Done() bool { | ||
return job.Status().Done() | ||
} | ||
|
||
func (job Job) Wait() bool { | ||
for !job.Done() { | ||
time.Sleep(time.Millisecond * 10) | ||
} | ||
return job.Success() | ||
} |
Oops, something went wrong.