Re: aborting getCurrentPosition()?

Hi Andrei,

Andrei Popescu <andreip@google.com> writes:

> Hi Max,
>
> On Wed, May 6, 2009 at 8:48 AM, Max Froumentin <maxfro@opera.com> wrote:
>> Hi,
>>
>> Was the possibility of aborting an asynchronous operation ever considered?
>> Either through abort(), a la XMLHttpRequest:
>>
>> var asyncOperation =  navigator.geolocation.getCurrentPosition(successCallback,  errorCallback, {maximumAge:600000});
>> // Waiting for success or callback, GPS Fix is taking time, user gets bored
>>
>
> Hmm, what is the exact motivation for this? If the user gets bored,
> you can just provide some 'cancel' button and set a flag so that when
> you eventually get the callback (either success or error) you don't
> react to it.

With an abort mechanism the callback would never be called after you've cancelled, whereas with the solution you suggest it could happen a while later, and could possibly interfere with subsequent calls to getCurrentPosition. And also, interrupting the GPS would save CPU cycles that would be wasted otherwise

And generally it would be simpler for script authors:
[[
var asyncOperation = navigator.geolocation.getCurrentPosition(successCallback, errorCallback, {maximumAge:600000});
button.onclick = function() { asyncOperation.abort(); }
]]
vs.
[[
var bored=0;
button.onclick = function() { bored=1 }
navigator.geolocation.getCurrentPosition(successCallback, errorCallback, {maximumAge:600000});
function successCallback() {
  if(bored==1) { bored=0; return }
  else
    ...
}

function errorCallback() {
  if(bored==1) { bored=0; return }
  else
    ...
}
]]

Max.

Received on Wednesday, 6 May 2009 12:52:47 UTC