Skip to content

Latest commit

 

History

History
56 lines (45 loc) · 1.35 KB

README.md

File metadata and controls

56 lines (45 loc) · 1.35 KB

@skyrocketjs/ember

A build chain for WebWorkers in Ember applications with intuitive ergonomics.

Installation

yarn add @skyrocketjs/ember @skyrocketjs/worker

Usage

To use a worker in your application or addon, you first have to define a new worker in a top-level workers/ directory in your project.

Example 1

workers/hello-world.js

import Worker, { method } from '@skyrocketjs/worker';

export default class HelloWorldWorker extends Worker {
  @method
  greet({ firstName, lastName }) {
    return `Welcome ${firstName} ${lastName}!`;
  }
}

Read 🚀@skyrocketjs/worker for full documentation of the features and APIs available to these workers.

Once you've defined a worker, you can use it from your application by injecting the worker (for instance into a route, component, controller or service);

Example 2

app/services/greeter.js

import Service from '@ember/service';
import { worker } from '@skyrocketjs/ember';

export default class GreeterService extends Service {
  @worker('hello-world') helloWorld;

  async getGreeting(firstName, lastName) {
    let greeting = await this.helloWorld.greet({ firstName, lastName });
    return greeting;
  }
}

License

This project is licensed under the MIT License.