forked from go-gst/go-gst
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.go
More file actions
31 lines (24 loc) · 705 Bytes
/
Copy pathcommon.go
File metadata and controls
31 lines (24 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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)
}
}