Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
Mathias Rangel Wulff edited this pageMar 14, 2017 ·5 revisions

WebWorker

There are some different versions of webworkers for AlaSQL

Option 1:

<scriptsrc="alasql-worker.js"></script><script>alasql('SELECT VALUE 1+1',[],function(res){console.log(res);});</script>

Include filealasql-worker.js on the page, and it will downloadalasql.min.js as a webworker. After that alasql() function will post message to webworker, and then return result value back. The webworker version of alasql() is async.

Try this examplehere.

If you want to load scripts into webworker you can use REQUIRE statement:

    alasql(['REQUIRE "script1.js", "script2.js"']).then(function(){// sql can usescript1.js    });

Usually this required for user-defined functions, like:

alasql.fn.myfn=function(x){returnx*x;}

Please note that webworkers does not support localStorage so this is not supported for AlaSQL running in a webworker.

Option 2:

<scriptsrc="alasql.js"></script><script>alasql.worker();alasql(['SELECT VALUE 1+1'].then(function(res){console.log(res);});</script>

Include filealasql.js on the page, and then run alasql.worker(). It will create new Worker based on the alasql.min.js. After that you can use AlaSQL as shown before. Again, the webworker version of alasql() is async.

Try this examplehere.

alasql.worker() function has three parameters:

alasql.worker()-startworkeralasql.worker("alasql.min.js")-startworkerfromspecifiedpathalasql.worker("alasql.min.js",["script1.js","script2.js"],callback)-loadadditionaljavascriptfiles.

Try these three examples:

Your option is number 2. Can you check it?

index1.html

<h1>Worker demo: simple worker</h1><p>See Console for worker results</p><script>varworker=newWorker('other-worker.js');</script>

other-worker.js

importScripts('../../console/alasql.min.js');if(alasql){console.log('AlaSQL is here?',alasql('SELECT VALUE TRUE'));console.log('self.onmessage is free?',!self.onmessage);}```;

© 2014-2026,Andrey Gershun &Mathias Rangel Wulff

Please help improve the documentation by opening a PR on thewiki repo

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp