-
Notifications
You must be signed in to change notification settings - Fork 283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: EventChannel #178
feat: EventChannel #178
Conversation
I'm making progress on the implementation. I had a hard time figuring out what to do when the user triggers a hot restart. Here is a example of a Golang EventChannel (Clickable), matching the sample found herepackage main
import (
"time"
"github.com/go-flutter-desktop/go-flutter"
"github.com/go-flutter-desktop/go-flutter/plugin"
)
var options = []flutter.Option{
flutter.PopBehavior(flutter.PopBehaviorClose), // on SystemNavigator.pop() closes the app
flutter.AddPlugin(&test{}),
}
const textinputChannelName = "com.yourcompany.eventchannelsample/stream"
type test struct {
stop chan bool
}
var _ flutter.Plugin = &test{}
func (p *test) InitPlugin(messenger plugin.BinaryMessenger) error {
p.stop = make(chan bool)
channel := plugin.NewEventChannel(messenger, textinputChannelName, plugin.StandardMethodCodec{})
// channel := plugin.NewEventChannel(messenger, textinputChannelName, plugin.JSONMethodCodec{})
channel.Handle(p)
print(channel)
return nil
}
func (p *test) OnListen(arguments interface{}, sink *plugin.EventSink) {
var i int32
i = 0
for {
select {
case <-p.stop:
return
default:
i++
time.Sleep(100 * time.Millisecond)
// print("\nsend\n")
sink.Success(i)
}
}
}
func (p *test) OnCancel(arguments interface{}) {
// I choose to use channels to Cancel events.
// Mutex can also work.
// I found that channels are bit more reliable than Mutex during hot restart.
p.stop <- true
} |
Waiting for a PR to be merged on flutter/engine #9781 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a spelling mistake and some formatting, otherwise looks good and can be merged!
I'll merge this PR once flutter/engine#9781 gets merged into master |
fixes #103
WIP.
Everything is good except for the
EndOfStream
impl flutter/flutter#35434.