Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Chrome 39 Brings Beacon API and ES6 Generators

Chrome 39 Brings Beacon API and ES6 Generators

This item in japanese

Google's Chrome team has released the stable version of Chrome 39: with updates including the Web Application Manifest specification, Beacon API, and support for ES6 generators.

According to the Chromium Dashboard the Web Application Manifest specification defines "a JSON-based manifest"

...which provides developers with a centralized place to put metadata associated with a web application. This includes, but is not limited to, the web application's name, links to icons, as well as the preferred URL to open when the user launches the web application.

The manifest also allows developers to declare a default orientation for their web application, as well as how the application is to be displayed by the user agent (e.g. in fullscreen).

The stable release of Chrome 39 also welcomes Beacon API, which is defined as "an interoperable means for site developers to asynchronously transfer small HTTP data from the User Agent to a web server."

Google's developer programs engineer Ewa Gasperowicz elaborates on Beacon in her article Send beacon data in Chrome 39, for HTML5 Rocks

Gasperowicz says, with Beacon,

You asynchronously send HTTP requests with small data payloads from a browser to a web server, without delaying other code in the page’s unload event or affecting the performance of the next page navigation.

The navigator.sendBeacon() method queues the data to be transmitted by the browser as soon as possible, but does not slow down navigation. It returns true if the browser is able to successfully queue the data for transfer. Otherwise it returns false.

Also on HTML5Rocks, in his article Generators: the Gnarly BitsGoogle developer relations engineer Jeff Posnick describes generators as:

special functions which create iterators, and iterators are objects that have a next() method, which can be called to obtain a value.

Within a generator function, the keyword yield provides the value for next(). Using yield suspends execution of the generator function, preserving the state until next() is called again, at which point the code starts back up and continues, until it yields another value (or until the generator function terminates).

By supporting ES6 generators, Chrome 39 allows developers to create iterators that pause their execution after yielding a value, and -- when invoked -- resume.

In the post Chrome 39 Beta: JS Generators, Animation Playback Control, and the WebApp Manifest Mounir Lamouri, Google software engineer, says this "greatly simplifies the process of developing asynchronous code and reduces dependence on callback functions."

However, on Reddit in the discussion Chrome 39 (now stable) ships with generator support, not everyone in the community was completely clear on the advantages of generators. User piglet24 asked "I don't understand how generators simplify code that is already async and using callbacks or promises. These look almost identical to yield return in C#."

User voidvector replied

I assume you know async/await in C#.

Both yield and await are syntax that suspense execution of the current function and allow for resume of said function at a later time with the same context. As such you can write a (coroutine) framework that implements the await usingyield and vice-versa. The abstract concept of "suspending execution of a function and resume later" is called Continuation. Both yield and async/await are forms of that.

A demo for generators can be found here:

Chrome 39 also includes 64-bit support for Mac and a number of security updates. The stable release of Chrome 40 is expected in January 2015.

Rate this Article