Niger
Niger

Reputation: 4006

Execute a javascript function in Asynchronous mode

We have AJAX calls to hit a URL. Do we have option to run/execute JavaScript function in Asynchronous mode?

Note: setTimeout() will execute that function after some seconds but still that will execute in Synchronous mode.

Upvotes: 2

Views: 672

Answers (2)

a paid nerd
a paid nerd

Reputation: 31522

No. JavaScript runs in a single thread per page.

You want HTML5 Web Workers. There's a good introduction on HTML5 Rocks.

However, the Google Gears plugin provides a WorkerPool:

WorkerPool API

The WorkerPool API allows web applications to run JavaScript code in the background, without blocking the main page's script execution.

There's also a proposal by the Gears team to add this to HTML5.

Upvotes: 4

Christian C. Salvadó
Christian C. Salvadó

Reputation: 827496

Most modern browsers implement JavaScript Web Workers, they provide a simple way to run scripts in background threads.

Check the following articles:

Upvotes: 3

Related Questions