0.0.10 • Published 2 years ago

swamper v0.0.10

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Maintenance Maintaner Website shields.io made-with-Markdown made-for-VSCode GitHub license Profile views GitHub contributors GitHub issues

GitHub forks GitHub stars GitHub watchers GitHub followers

swamper

Swamper is a webpack loader and wrapper around worker-loader.

Installation

First you need to install swamper webpack loader and swamper package:

yarn add swamper swamper-loader

Add webpack rules:

// ...
{
  test: /\.worker\.(c|m)?js$/i,
  use: [
    {
      loader: 'worker-loader',
      options: {
        publicPath: '/scripts/workers/',
      },
    },
    {
      loader: 'swamper-loader',
    },
  ],
},
// ...

Example

math.worker.js

export default class MathWorker {
  // On worker create
  init () {
    this.emit('eventName', arg1, arg2, ...);

    this.on('eventName', (arg1, arg2, ...) => {
      // ...
    });
  }

  async add(a, b) {
    return a + b;
  }
}

index.js

import swamper from 'swamper';
import MathWorker from './math.worker';

swamper(MathWorker).then(async worker => {
  worker.on('eventName', (arg1, arg2, ...) => {
    // ...
  });

  worker.emit('eventName', arg1, arg2, ...);

  const result = await worker.add(1, 2);
  console.log(result); // 3
});
0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago