The solution I've gone with, for this exact same scenario is:

var inScope = true;
callSometimesAsyncFn(function() {
  if (inScope) {
    cb();
  }
  else {
    $rootScope.$apply(cb);
  }
});
inScope = false;

That way, if it callback is called synchronously, its not wrapped in a 
scope.$apply, but if its async, it is.

Adam



On Tuesday, April 16, 2013 at 3:48:52 PM UTC-5, Davis Ford wrote:
>
> I did solve it -- thanks to you suggestion that perhaps it wasn't 
> executing async...well the API is async (i.e. takes a callback), but it is 
> implemented by taking a function as a parameter, and then down in the guts 
> somewhere just doing a fn.call(null, params). 
>
> It is more complicated -- there is an emulator with stubbed out native 
> code, and then there's the real platform -- where it does execute 
> asynchronously b/c it crosses a native bridge.  So in the emulator, it 
> behaves synchronously, and on the target hardware it behaves asynchronously.
>
> I solved it (complete hack) by wrapping it with 
>
> setTimeout(function () {
>   callSometimesAsyncFn( cb );
> }, 0);
>
> with a timeout value of zero.  This forces a nextTick();
>
> On Tue, Apr 16, 2013 at 4:19 PM, Josh David Miller <[email protected] 
> <javascript:>> wrote:
>
>> Hmm... the issue must be within the native counterpart. Perhaps part of 
>> it is blocking. The only suggestion I have is to add a bunch of console.log 
>> statements throughout the code to see if you can establish the current 
>> execution order. Unfortunately, without code I don't have a better 
>> suggestion. :-(
>>
>> Out of curiosity, what is the native component?
>>
>> Good luck!
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to