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

How to use Sharedworker? #24316

Closed
shamhub opened this issue May 22, 2018 · 2 comments
Closed

How to use Sharedworker? #24316

shamhub opened this issue May 22, 2018 · 2 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@shamhub
Copy link

shamhub commented May 22, 2018

Below code uses dedicated worker, in the worker code.

const ctx: Worker = self as any;
ctx.addEventListener('message', (e) => {
    // console.log(e)
    if (e.data === 'do some work') {
        console.log('Worker is about to start some work');
        let count: number = 0;
        for (let i: number = 0; i < 1000; i++) {
            count += i;
        }
        ctx.postMessage({ message: count });
    }
})

where the calling code is:

let worker: Worker = new Worker('worker.js');
worker.postMessage('do some work');

and tsconfig.json is:

{
   
    "compilerOptions": {
   
      "lib": ["es2015", "dom"]
    },
    "files": [
      "./1_webworker/tstut.ts",
      "./1_webworker/worker.ts"

    ]
  }


Trying to execute the same code using let worker: SharedWorker = new SharedWorker('worker.js'); but got the error Cannot find name 'SharedWorker'

here is the folder structure

How to use SharedWorker in place of dedicated worker?

@RyanCavanaugh
Copy link
Member

It looks like this is a question rather than a bug report. This issue tracker is for tracking bugs and active work on TypeScript itself, rather than a general forum for programmers using TypeScript to get help or ask questions.

You can ask questions on sites like Stack Overflow. We are not able to provide one-on-one support on the issue tracker. Next time, please read the issue template carefully - it has important information on what kinds of reports can be acted on here, as well as links to useful TypeScript resources. Thanks!

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label May 22, 2018
@mhegazy
Copy link
Contributor

mhegazy commented May 22, 2018

SharedWorker is currently not defined in lib.d.ts, meanwhile you can use @types/sharedworker.

Logged #24323 to track adding it.

@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants