A deeper look at event loop (micro/macro tasks)

One common question So why the result is 1,2,3,5,4 rather than 1,2,3,4,5? If we look at the detail, looks like the async of setTimeout is different from the async of Promise.then, at least they are not in the same async queue. The answer is here in the whatwg SPEC. An event loop has one or more task queues.(task…

Write my own small Promise

Having been using promise day to day in Angularjs / Nodejs, but never get a chance to look at the actual implement of it. Today I tried to write a simple version of Promise on my own. It turns out to be pretty interesting. 1st version – Basic classes(Promise and Deferred) First we need some…

$q and $promise in angularjs

$q and $promise The traditional way to deal with asynchronous tasks in Javascript are callbacks; call a method, give it a function reference to execute once that method is done. 1 2 3 $.get(‘api/gizmo/42’, function(gizmo) {   console.log(gizmo); // or whatever }); This is pretty neat, but, it has some drawbacks; for one, combining or chaining…

understanding the angular js $resource

$Resource Basic At first sight AngularJS seems like a magical framework, which does some weird but awesome things like dependency injection, data binding only by setting a single property to the magical object named $scope and many other things. If you look at the source code of Angular you’ll see a lot of smart and…