The callback function can always set a non local variable so it's
visible by the other functions. Although you might as well go for a
better pattern depending on the needs of your extension.

Ernest

On Sun, Jan 3, 2010 at 5:25 PM, Erek Speed <melin...@gmail.com> wrote:
> Hi,
>
> So I realized this was working but that my code which checked the
> variable was running before the callback.
>
> This lead to a different problem where I can't ever know the status of
> a message in the same function that sent the message.  Or even in a
> few functions later due to the delay.
>
> I tried to get synchronous messages by spinning in a loop checking a
> status variable, but it seems that in JS, while the loop is running
> nothing else happens.  Probably because the extension is all in one
> thread.
>
> Right now, I'm planning on refactoring my code to a more chrome
> friendly manner but it seems that it could be good to be able to know
> the that a message succeeded at some specified point of time instead
> of a vague time in the future.
>
> Erek
>
> On Sat, Jan 2, 2010 at 6:48 AM, Erek Speed <melin...@gmail.com> wrote:
>> I want to set a variable from inside my callback to a sendRequest
>> function.
>>
>> The mappy extension gives an example of doing this but I can't seem to
>> manage it using global or local variables.
>>
>> Here's mappy's code for reference:
>> <script>
>> // Global accessor that the popup uses.
>> var addresses = {};
>> var selectedAddress = null;
>> var selectedId = null;
>>
>> function updateAddress(tabId) {
>>  chrome.tabs.sendRequest(tabId, {}, function(address) {
>>    addresses[tabId] = address;
>>    if (!address) {
>>      chrome.pageAction.hide(tabId);
>>    } else {
>>      chrome.pageAction.show(tabId);
>>      if (selectedId == tabId) {
>>        updateSelected(tabId);
>>      }
>>    }
>>  });
>> }
>> ...
>>
>> In the response function, address is changed which is convenient.
>> What is it about addresses that let's it retain value even in the
>> mystical space of messages?
>>
>> --
>>
>> You received this message because you are subscribed to the Google Groups 
>> "Chromium-extensions" group.
>> To post to this group, send email to chromium-extensi...@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> chromium-extensions+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/chromium-extensions?hl=en.
>>
>>
>>
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Chromium-extensions" group.
> To post to this group, send email to chromium-extensi...@googlegroups.com.
> To unsubscribe from this group, send email to 
> chromium-extensions+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/chromium-extensions?hl=en.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"Chromium-extensions" group.
To post to this group, send email to chromium-extensi...@googlegroups.com.
To unsubscribe from this group, send email to 
chromium-extensions+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/chromium-extensions?hl=en.


Reply via email to