mirror of
https://github.com/go-gst/go-gst.git
synced 2025-09-26 20:11:18 +08:00
32 lines
705 B
Go
32 lines
705 B
Go
package examples
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/go-gst/go-glib/glib"
|
|
)
|
|
|
|
// Run is used to wrap the given function in a main loop and print any error
|
|
func Run(f func() error) {
|
|
mainLoop := glib.NewMainLoop(glib.MainContextDefault(), false)
|
|
|
|
go func() {
|
|
if err := f(); err != nil {
|
|
fmt.Println("ERROR!", err)
|
|
}
|
|
mainLoop.Quit()
|
|
}()
|
|
|
|
mainLoop.Run()
|
|
}
|
|
|
|
// RunLoop is used to wrap the given function in a main loop and print any error.
|
|
// The main loop itself is passed to the function for more control over exiting.
|
|
func RunLoop(f func(*glib.MainLoop) error) {
|
|
mainLoop := glib.NewMainLoop(glib.MainContextDefault(), false)
|
|
|
|
if err := f(mainLoop); err != nil {
|
|
fmt.Println("ERROR!", err)
|
|
}
|
|
}
|