Re: Getting the result of a DBus method call.
- From: Amy <mathematical coffee gmail com>
- To: "Jasper St. Pierre" <jstpierre mecheye net>
- Cc: gnome-shell-list gnome org
- Subject: Re: Getting the result of a DBus method call.
- Date: Thu, 4 Oct 2012 16:52:47 +1000
Aha, thanks! Sync was what I was after. It's taking a while though, so
I will restructure my code to use the Remote methods.
On 4 October 2012 16:48, Jasper St. Pierre <jstpierre mecheye net> wrote:
> Use "Sync" instead of "Remote". Note that if the DBus call takes a
> long time, this will freeze the Shell, so consider using Remote by
> restructuring your code:
>
> dbusProxy.<methodname>Remote(/* arguments ... */, function (result) {
> // Continue your code here, rather than below the DBus call.
> });
>
> For your information, this style of code is called "continuation
> passing", and it can get unwieldy very quickly as your callbacks pile
> up. In future versions of ECMAScript, they'll allow things called
> Promises, so you can do:
>
> let promise = dbusProxy.<methodname>Remote(/* arguments ... */);
> promise.addCallback(function(result) {
> // Continue your code here, rather than than below the DBus call.
> });
>
> Although this may not seem like such a big change, given that promises
> are like any other object, you can return a promise instead of having
> to take callbacks as arguments to be passed all the way down the
> chain.
>
> Also, trampolines:
>
> yield let result = dbusProxy.<methodname>Remote(/* arguments ... */);
>
> On Thu, Oct 4, 2012 at 2:40 AM, Amy <mathematical coffee gmail com> wrote:
>> Hi all,
>>
>> I'm taking first steps learning how to use DBus in a gnome shell extension.
>>
>> I've hit a stumbling block - how do I get the result of a remote
>> method immediately?
>>
>> Something like:
>>
>> let value = dbusProxy.<methodname>Remote(/* arguments ... */,
>> function (result) { ???? how to return it???? });
>>
>> In the usage above, I want the `result` in the callback to be assigned
>> to value so that if my next line of code is (say)
>>
>> log(value);
>>
>> this will be up-to-date.
>>
>> Otherwise, I could do something like:
>>
>> let value;
>> dbusProxy.<methodname>Remote(/* arguments ... */, function
>> (result) { value = result; });
>> log(value);
>>
>> but when I do this, 'value' is not up to date (until the callback
>> completes), so I can't rely on the above code if I want to use 'value'
>> straight away.
>>
>> Is there some way around this?
>> _______________________________________________
>> gnome-shell-list mailing list
>> gnome-shell-list gnome org
>> https://mail.gnome.org/mailman/listinfo/gnome-shell-list
>
>
>
> --
> Jasper
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]