npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

inline-iso-worker

v0.4.2

Published

Worker que trabalha com callbacks no lugar de arquivos

Downloads

6

Readme

inline-iso-worker 🇧🇷

Coverage Status

Isomorfic worker that works with inline callbacks instead of files.

Installation

npm install inline-iso-worker

yarn add inline-iso-worker

Inline worker

Default package export.

Constructors

constructor<TScope, TCallback>(scope: TScope, callback: TCallback)

Creates a worker with the specified scope and callabck. The scope will be assigned to the function's lexical this. An exception will occur if a arrow function is provided. The rest of the arguments will be the arguments provided to the run() method.

constructor<TScope>(callback: TCallback)

Creates a worker without scope and with the specified callback. An arrow function can also be provided.

Methods

async run(...args: Parameters<TCallback>): Promise<ReturnType<TCallback>>

Performs the callback provided in the constructor with the given arguments and returns the resulting value from the callback.

Example

import InlineWorker from 'inline-iso-worker'

const worker = new InlineWorker({ prefix: 'Hello ', suffix: '. Be welcome', }, function(name: string) {
  return this.prefix + name + this.suffix
})

async someConcurrentFunction() {
  const return1 = await worker.run('Filipe')
  const return2 = await worker.run('Roberto')
  const return3 = await worker.run('Beck')

  console.log(return1) // Prints "Hello Filipe. Be welcome"
  console.log(return2) // Prints "Hello Roberto. Be welcome"
  console.log(return3) // Prints "Hello Beck. Be welcome"
}

Cluster

Handles multiple workers who performs the same callback synchronously.

Constructors

constructor<TScope, TCallback>(scopes: Scope[], callback: TCallback)

Creates a cluster containing a worker for each provided scope, all sharing the specified callback.

Methods

async run(...args: Parameters<TCallback>): Promise<ReturnType<TCallback>[]>

Performs the callback provided in the constructor with the provided arguments for each worker and returns an array with the resulting values from each worker. If the return value is a Promise, returns the resolved value.

Example

import { Cluster } from 'inline-iso-worker'

const scopes = [{
  prefix: 'Hello ', suffix: '. Be welcome',
  prefix: 'Bye ', suffix: '',
  preffix: '', suffix: ''
}]

const cluster = new Cluster(scopes, function(name: string) {
  return this.prefix + name + this.suffix
})

async someConcurrentFunction() {
  const [return1, return2, return3] = await cluster.run('Filipe')

  console.log(return1) // Prints "Hello Filipe. Be welcome"
  console.log(return2) // Prints "By Filipe"
  console.log(return3) // Prints "Filipe"
}

🇧🇷

[pt-BR]

Worker isomórfico que trabalha com callbacks inline no lugar de arquivos.

Instalação

npm install inline-iso-worker

yarn add inline-iso-worker

Inline worker

Exportação default do pacote.

Construtores

constructor<TScope, TCallback>(scope: TScope, callback: TCallback)

Cria um Worker com o escopo e callback especificados. O escopo será atribuido ao this léxico da função. Ocorrerá uma exceção se uma arrow function for fornecida. Os demais argumentos serão os argumentos fornecidos ao método run().

constructor<TScope>(callback: TCallback)

Cria um worker sem escopo e com o callback especificado. Uma arrow function também pode ser fornecida.

Métodos

async run(...args: Parameters<TCallback>): Promise<ReturnType<TCallback>>

Executa o callback fornecido no construtor com os argumentos fornecidos e retorna o valor resultante do callback.

Exemplo

import InlineWorker from 'inline-iso-worker'

const worker = new InlineWorker({ prefix: 'Olá ', suffix: '. Seja bem vindo', }, function(name: string) {
  return this.prefix + name + this.suffix
})

async someConcurrentFunction() {
  const return1 = await worker.run('Filipe')
  const return2 = await worker.run('Roberto')
  const return3 = await worker.run('Beck')

  console.log(return1) // Imprime "Olá Filipe. Seja bem vindo"
  console.log(return2) // Imprime "Olá Roberto. Seja bem vindo"
  console.log(return3) // Imprime "Olá Beck. Seja bem vindo"
}

Cluster

Manipula múltiplos workers que executam o mesmo callback de forma sincronizada.

Construtores

constructor<TScope, TCallback>(scopes: Scope[], callback: TCallback)

Cria um Cluster contendo um worker para cada escopo fornecido, todos compartilhando o callback especificado.

Métodos

async run(...args: Parameters<TCallback>): Promise<ReturnType<TCallback>[]>

Executa o callback fornecido no construtor com os argumentos fornecidos para cada worker e retorna um array com os valores resultantes de cada worker. Se o valor de retorno for uma Promise, retorna o valor resolvido.

Exemplo

import { Cluster } from 'inline-iso-worker'

const scopes = [{
  prefix: 'Olá ', suffix: '. Seja bem vindo',
  prefix: 'Tchau ', suffix: '',
  preffix: '', suffix: ''
}]

const cluster = new Cluster(scopes, function(name: string) {
  return this.prefix + name + this.suffix
})

async someConcurrentFunction() {
  const [return1, return2, return3] = await cluster.run('Filipe')

  console.log(return1) // Imprime "Olá Filipe. Seja bem vindo"
  console.log(return2) // Imprime "Tchau Filipe"
  console.log(return3) // Imprime "Filipe"
}