Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- make worker.sql-wasm.js isomorphic (will load in web-worker, nodejs, and browser without errors). #376

Closed
wants to merge 2 commits into from

Conversation

kaizhu256
Copy link
Member

this pull-request simplifies devops/product-development
by removing the need to choose between worker and non-worker-variant js-file.

since worker.sql-wasm.js is now isomorphic, it can be used in non-worker context as well, e.g.:

<html>
<body>
<!-- use worker.sql-wasm.js in non-web-worker env -->
<script src="dist/worker.sql-wasm.js"></script>
<script>
(async function () {
    "use strict"
    var sql = await initSqlJs();
    var db = new sql.Database();
    ...
}());
</script>
</body>
</html>

the change to src/worker.js is less drastic than it seems. i simply indented/wrapped worker code in isomorphic wrapper:

// encapsulate web-worker code to run in any env
(function () {
    "use strict";

    // isomorphism - do not run worker.js code if not in web-worker env
    if (!(
        typeof self === "object"
        && typeof importScripts === "function"
        && typeof self
        && self.importScripts === importScripts
    )) {
        return;
    }

    ...

}());

i've successfully deployed and used this one-size-fits-all worker.sql-wasm.js in both worker and non-worker applications for the past 3 months.

@lovasoa
Copy link
Member

lovasoa commented Mar 31, 2020

This PR looks okay to me. But maybe we should have the discussion about removing the worker code before integrating new changes to it. I'll open a new issue about that.

See: #377

@kaizhu256
Copy link
Member Author

k, blocked on outcome of pending worker-discussion. this is actually the first of maybe 3 worker pull-requests i have in mind to improve worker-usability.

@kaizhu256
Copy link
Member Author

closing this pull-request as superseded by #378

@kaizhu256 kaizhu256 closed this Apr 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants