Skip to content

sampbarrow/observable-worker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Observable Worker

Installation

Usage

In the main file:

import { wrapWorker } from "observable-worker"
import { Observable } from "rxjs"

type WorkerService = {

    observeValue(): Observable<number>
    getValue(): Promise<number>

}

const worker = wrapWorker<WorkerService>(new URL("/src/app/DedicatedWorker.ts", import.meta.url), { type: 'module' })
worker.observeValue().observe().subscribe(value => {
    console.log("Got a value: " + value + ".)
})
worker.getValue().execute().then(value => {
    console.log("Got a value: " + value + ".)
})

In the worker file:

import { exposeSelf } from "observable-worker"
import { interval, map } from "rxjs"

exposeSelf({
    target: {
        observeValue() {
            return interval(500).pipe(map(() => Math.random()))
        }
    }
})

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published