gapi: Allow the GAPI implementer to specify fast and exit
This allows the implementer of the GAPI to specify three parameters for every Next message sent on the channel. The Fast parameter tells the agent if it should do the pause quickly or if it should finish the sequence. A quick pause means that it will cause a pause immediately after the currently running resources finish, where as a slow (default) pause will allow the wave of execution to finish. This is usually preferred in scenarios where complex graphs are used where we want each step to complete. The Exit parameter tells the engine to exit, and the Err parameter tells the engine that an error occurred.
This commit is contained in:
@@ -75,35 +75,39 @@ func (obj *MyGAPI) Graph() (*pgraph.Graph, error) {
|
||||
}
|
||||
|
||||
// Next returns nil errors every time there could be a new graph.
|
||||
func (obj *MyGAPI) Next() chan error {
|
||||
ch := make(chan error)
|
||||
func (obj *MyGAPI) Next() chan gapi.Next {
|
||||
ch := make(chan gapi.Next)
|
||||
obj.wg.Add(1)
|
||||
go func() {
|
||||
defer obj.wg.Done()
|
||||
defer close(ch) // this will run before the obj.wg.Done()
|
||||
if !obj.initialized {
|
||||
ch <- fmt.Errorf("%s: MyGAPI is not initialized", obj.Name)
|
||||
next := gapi.Next{
|
||||
Err: fmt.Errorf("%s: MyGAPI is not initialized", obj.Name),
|
||||
Exit: true, // exit, b/c programming error?
|
||||
}
|
||||
ch <- next
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("%s: Generating a bunch of new graphs...", obj.Name)
|
||||
ch <- nil
|
||||
ch <- gapi.Next{}
|
||||
log.Printf("%s: New graph...", obj.Name)
|
||||
ch <- nil
|
||||
ch <- gapi.Next{}
|
||||
log.Printf("%s: New graph...", obj.Name)
|
||||
ch <- nil
|
||||
ch <- gapi.Next{}
|
||||
log.Printf("%s: New graph...", obj.Name)
|
||||
ch <- nil
|
||||
ch <- gapi.Next{}
|
||||
log.Printf("%s: New graph...", obj.Name)
|
||||
ch <- nil
|
||||
ch <- gapi.Next{}
|
||||
log.Printf("%s: New graph...", obj.Name)
|
||||
ch <- nil
|
||||
ch <- gapi.Next{}
|
||||
log.Printf("%s: New graph...", obj.Name)
|
||||
ch <- nil
|
||||
ch <- gapi.Next{}
|
||||
log.Printf("%s: New graph...", obj.Name)
|
||||
ch <- nil
|
||||
ch <- gapi.Next{}
|
||||
log.Printf("%s: New graph...", obj.Name)
|
||||
ch <- nil
|
||||
ch <- gapi.Next{}
|
||||
time.Sleep(1 * time.Second)
|
||||
log.Printf("%s: Done generating graphs!", obj.Name)
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user