Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-workman-worker

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-workman-worker

Worker library for node-workman

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Worker for Work(er) Man(ager)

Worker library for node-workman.

Written in TypeScript and the definitions (.d.ts -files) are published in NPM with the rest of the files.

Usage

Add the library with yarn

yarn add node-workman-worker

Or with NPM

npm install node-workman-worker

Then import the library in your code

import {worker} from "node-workman-worker"

Create your task handlers

interface Calculation {
    a: number
    b: number
}

async function work(data: Calculation): Promise<any> {
    return data.a + data.b
}

async function waitAndWork(data: Calculation): Promise<any> {
    return new Promise<any>(function(resolve: {(result: any): void}) {
        setTimeout(function() {
            resolve(data.a + data.b)
        }, 1000)
    })
}

And register them before running the core worker logic.

worker.registerTask("work", work)
worker.registerTask("wait", waitAndWork)
worker.run({
    server: "ws://localhost:9999/worker"
})

That's it. Nothing more required. Simple, right?

You can check the full example src/test-worker.ts

Contributing

Pull requests and issues are open for any good ideas, but please keep in mind that this is supposed to stay fairly simple. If in doubt, open an issue to ask if your proposed idea would be accepted.

Development

To run the typescript compiler and the test worker (src/test-worker.ts) just run:

yarn dev

Licensing

MIT. Need a more open license? Just ask.

FAQs

Package last updated on 23 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc