Skip to content
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

Replace callbacks with streams #81

Closed
robert-ancell opened this issue Aug 25, 2020 · 1 comment
Closed

Replace callbacks with streams #81

robert-ancell opened this issue Aug 25, 2020 · 1 comment

Comments

@robert-ancell
Copy link
Contributor

robert-ancell commented Aug 25, 2020

Currently you register callbacks to handle signals:

var client = DBusClient.session();
var subscription = await client.subscribeSignals((path, interface, member, values) {
  var count = (values[0] as DBusUint64).value;
  print('Ping ${count}!');
}, sender: 'com.example.DartTest');
...
client.unsubscribeSignals();

I think the more Dart way of doing things is to use a stream, which would give an API like this:

var stream = await client.subscribeSignals(sender: 'com.example.DartTest');
await for (signal in stream) {
  var count = (signal.values[0] as DBusUint64).value;
  print('Ping ${count}!')
}

or with callbacks:

var stream = await client.subscribeSignals(sender: 'com.example.DartTest');
var subscription = stream.listen((signal) {
  var count = (signal.values[0] as DBusUint64).value;
  print('Ping ${count}!')
});
...
subscription.cancel();
@robert-ancell
Copy link
Contributor Author

The reason the current implementation doesn't use streams is I wasn't experienced enough with Dart at the time to work out how to do it so I just started with callbacks.

robert-ancell added a commit to robert-ancell/dbus.dart that referenced this issue Sep 14, 2020
robert-ancell added a commit to robert-ancell/dbus.dart that referenced this issue Sep 14, 2020
robert-ancell added a commit to robert-ancell/dbus.dart that referenced this issue Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant