Git Product home page Git Product logo

web-threads's Introduction

logomakr_09u4zz

Build Status codecov npm GitHub license Maintenance

generic threads using web workers for the web

Installation

add it to your project using npm install web-threads --save or yarn add web-threads

Usage

Simple function with arguments

import { execute } from 'web-threads'

let func = (value) => {
    return value * value
}
let params = {
    fn: func.toString(),
    args: [2]
} 
execute(params)
    .then(console.log)
    .catch(console.error)

Function with context

import { execute } from 'web-threads'

function Func(value){
    this.value = value
}
Func.prototype.foo = function(){
    return this.value * this.value
};
var instance = new Func(2)
let params = {
    fn: instance.foo,
    context: instance
} 
execute(params)
    .then(console.log)
    .catch(console.error)

Function with context and arguments

import { execute } from 'web-threads'

function Func(value){
    this.value = value
}
Func.prototype.foo = function(otherValue){
    return this.value * otherValue
};
var instance = new Func(2)
let params = {
    fn: instance.foo,
    context: instance,
    args: [4]
} 
execute(params)
    .then(console.log)
    .catch(console.error)

ES6 class call function with arguments

import { execute } from 'web-threads'

class someClass {
    constructor(val){
        this.val = val
    }
    foo(some){
        return this.val * some
    }
}

var instance = new someClass(2)
let params = {
    fn: instance.foo,
    context: instance,
    args: [4]
} 
execute(params)
    .then(console.log)
    .catch(console.error)

Inspired in:

Web graphic by picol from Flaticon is licensed under CC BY 3.0. Check out the new logo that I created on LogoMakr.com https://logomakr.com/09u4Zz

web-threads's People

Contributors

github-actions[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

rajanzhan

web-threads's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.