Return channel from run method

This commit is contained in:
Sasha Koshka 2022-11-09 01:18:56 -05:00
parent 11bdae78a0
commit e7b5136ea6
4 changed files with 9 additions and 9 deletions

View File

@ -18,12 +18,12 @@ func (application *Application) SetTitle (title string) {
application.backend.SetTitle(title) application.backend.SetTitle(title)
} }
// Run initializes the application, and then calls callback. Operations inside // Run initializes the application, starts it, and then returns a channel that
// of callback are allowed to interact with the application. Depending on the // broadcasts events. If no suitable backend can be found, an error is returned.
// backend used, this function may bind to the main thread.
func (application *Application) Run ( func (application *Application) Run (
callback func (application *Application), callback func (application *Application),
) ( ) (
channel chan(Event),
err error, err error,
) { ) {
// default values for certain parameters // default values for certain parameters
@ -44,7 +44,7 @@ func (application *Application) Run (
application.backend, err = instantiateBackend(application) application.backend, err = instantiateBackend(application)
if err != nil { return } if err != nil { return }
application.backend.Run(callback) channel = application.backend.Run()
return return
} }

View File

@ -1,11 +1,10 @@
package stone package stone
import "time"
import "image" import "image"
import "errors" import "errors"
type Backend interface { type Backend interface {
Run () (chan(Event)) Run () (channel chan(Event))
SetTitle (title string) SetTitle (title string)
SetIcon (icons []image.Image) SetIcon (icons []image.Image)
} }

View File

@ -1,7 +1,8 @@
package application package stone
type Event interface { } type Event interface { }
type EventQuit struct { }
type EventPress Button type EventPress Button
type EventRelease Button type EventRelease Button
type EventResize struct { } type EventResize struct { }

View File

@ -3,7 +3,7 @@ package main
import "fmt" import "fmt"
import "time" import "time"
import "git.tebibyte.media/sashakoshka/stone" import "git.tebibyte.media/sashakoshka/stone"
import _ "git.tebibyte.media/sashakoshka/stone/backends/pixel" // import _ "git.tebibyte.media/sashakoshka/stone/backends/x"
func main () { func main () {
application := stone.Application { } application := stone.Application { }