An open API service indexing awesome lists of open source software.

https://github.com/technote-space/worker-controller

Worker Controller
https://github.com/technote-space/worker-controller

Last synced: 8 months ago
JSON representation

Worker Controller

Awesome Lists containing this project

README

          

# Worker Controller

[![npm version](https://badge.fury.io/js/%40technote-space%2Fworker-controller.svg)](https://badge.fury.io/js/%40technote-space%2Fworker-controller)
[![CI Status](https://github.com/technote-space/worker-controller/workflows/CI/badge.svg)](https://github.com/technote-space/worker-controller/actions)
[![CodeFactor](https://www.codefactor.io/repository/github/technote-space/worker-controller/badge)](https://www.codefactor.io/repository/github/technote-space/worker-controller)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/technote-space/worker-controller/blob/main/LICENSE)

Worker Controller

## Table of Contents

Details

- [Setup](#setup)
- [Author](#author)

## Setup
```shell script
yarn add @technote-space/worker-controller
```

`Pgocess.ts`
```typescript
import {ProcessBase} from '@technote-space/worker-controller';
import {UpdateResult} from './types';

global['Process'] = class Process extends ProcessBase {
//...
};
```

`webpack.js`
```js
module.exports = {
//...
entry: {
index: path.join(__dirname, 'src/index.jsx'),

// create worker-controller.worker.js
'worker-controller.worker': '@technote-space/worker-controller/dist/Worker/worker-controller.worker',
// create process.js
process: path.join(__dirname, 'src/Process'),
},
output: {
//...
filename: '[name].js',
},
//...
};
```

`Run.jsx`
```typescript jsx
import React, {useEffect, useMemo, useState} from 'react';
import {Button} from '@material-ui/core';
import {Controller} from '@technote-space/worker-controller';

export default function NavContentEx() {
const [worker, setWorker] = useState(null);

useEffect(() => {
const worker = new Controller(result => {
//...
});
setWorker(worker);
worker.reset();
}, []);

return useMemo(() => !worker ? null : <>
worker.reset()}>Reset
worker.start()}>Start
worker.stop()}>Stop
>, [worker])
}
```

## Author
[GitHub (Technote)](https://github.com/technote-space)
[Blog](https://technote.space)