0.0.12 • Published 7 months ago

osra v0.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

osra

what that? https://github.com/GoogleChromeLabs/comlink but nicer to use. thats about it

how to? register your functions in the other context like so

import { makeCallListener, registerListener } from 'osra'

const resolvers = {
  'test': makeCallListener(async (myData) => {
    // do work...
    return {
      foo: 1,
      bar: 'bar',
      baz: () => true
    }
  })
}

registerListener({ target: globalThis, resolvers })

and on your current context you can call it easily like

import { call } from 'osra'

const worker = new Worker('/worker.js', { type: 'module' })

call(worker)('test', { theDataThatWillBeSentToTheOtherContext: 1 })
      .then(({ foo, bar, baz }) => {
        // foo === 1
        // bar === 'bar'
        // baz === callable function that will return a promise with its response
      })

all types of data supported by osra that will be correctly proxied/sent to the other context in addition of functions:

export type TransferableObject =
  ArrayBuffer | MessagePort | ReadableStream | WritableStream |
  TransformStream | /* AudioData | */ ImageBitmap /* | VideoFrame | OffscreenCanvas */

export interface StructuredCloneObject {
  [key: string | number | symbol]: StructuredCloneType
}

export type StructuredCloneType =
  boolean | null | undefined | number | BigInt | string | Date | RegExp | Blob | File | FileList | ArrayBuffer | ArrayBufferView |
  ImageBitmap | ImageData | Array<StructuredCloneType> | StructuredCloneObject | Map<StructuredCloneType, StructuredCloneType> | Set<StructuredCloneType>

export interface StructuredCloneTransferableObject {
  [key: string | number | symbol]: StructuredCloneTransferableType
}

export type StructuredCloneTransferableType =
  StructuredCloneType | TransferableObject | Array<StructuredCloneTransferableType> | StructuredCloneTransferableObject |
  Map<StructuredCloneTransferableType, StructuredCloneTransferableType> | Set<StructuredCloneTransferableType>
0.0.12

7 months ago

0.0.11

8 months ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

2 years ago

0.0.3

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.6

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago