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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@makecode/worker-manager

v1.0.0

Published

워커 관리

Readme

@makecode/worker-manager

@makecode/worker-manager는 Node.js 및 브라우저 환경에서 쉽게 사용할 수 있는 Queryable Worker Manager 라이브러리입니다. 이 라이브러리는 Worker와 메시지 핸들링을 간단하게 설정하고 사용할 수 있도록 도와줍니다.

설치

npm install @makecode/worker-manager

또는

yarn add @makecode/worker-manager

주요 기능

  • 브라우저와 Node.js 환경 모두 지원
  • Worker 메시지 핸들링
  • queryable 객체를 통해 Worker 내부에서 함수 호출 가능
  • Worker 파일 내부 실행 함수가 동기/비동기 경우, 응답 후 결과 실행 보장할 수 있음

사용 방법

브라우저 환경에서 사용하기

import { createCodeBlockURL, QueryableWorker } from '@makecode/worker-manager';

// Worker 스크립트
const codeURL = createCodeBlockURL`
  const globalContext =
    typeof global !== 'undefined'
      ? global // Node.js 환경
      : typeof self !== 'undefined'
        ? self // Web Worker 환경
        : this;

  const queryable = {
    hello(name) {
      return `Hello, ${name}!`;
    },
    world(payload) {
      return new Promise((resolve, reject) => {
        const numberRandom = (max=1, min=0) => {
          if(min >= max) {
            return max;
          }
          return Math.floor(Math.random() * (max - min) + min);
        }
        const seconds = numberRandom(9000, 1000);
        setTimeout(() => {
          resolve([seconds, payload]);
        }, seconds);
      });
    }
  };

  globalContext.onmessage = async (data, postMessage) => {
    const { query, payload } = data;
    const result = await queryable[query]?.(...payload);
    postMessage({ query, result });
  };
`;

//const blob = new Blob([workerScript], { type: 'application/javascript' });
//const codeURL = URL.createObjectURL(blob);
const worker = new QueryableWorker(codeURL, {
  workerOptions: { type: 'module' },
  onMessage: message =>
    console.log('exampleCodeBlockURL', '워커로부터의 메시지', message),
  onError: error => console.error('exampleCodeBlockURL', '워커 오류', error),
});
worker.connect(); // 워커 연결
worker.addListener('hello', event =>
  console.log(
    'exampleCodeBlockURL',
    '워커 동기 실행 함수 결과 수신',
    event.detail,
  ),
);
worker.addListener('world', event =>
  console.log(
    'exampleCodeBlockURL',
    '워커 비동기 실행 함수 결과 수신',
    event.detail,
  ),
);

// 쿼리 형태가 아닌 경우
worker.postMessage('일반 메시지 워커로 전달!');

// 쿼리 형태 전송, 비동기 (호출순서에 따른 응답 실행순서 비보장)
worker.postQuery('hello', 2, 1);

// 쿼리 형태 전송, 동기 (호출순서에 따른 응답 실행순서 보장)
worker.postQuerySync('world', 'test1');
worker.postQuerySync('world', 'test2');
worker.postQuerySync('world', 'test3');
worker.postQuerySync('world', 'test4');

Node.js 환경에서 사용하기

...

API

QueryableWorker

Worker 인스턴스 생성, 순서 제어 등

createCodeBlockURL

code string > blob > URL

createCodeBlockURL``; Tagged templates 사용

queryable

Worker 내부에서 정의되는 함수 집합입니다. 각 함수는 문자열로 호출될 수 있으며, payload를 매개변수로 받습니다.

queryableMessageHandler

메시지를 처리하는 핸들러로, Worker에서 수신된 데이터를 기반으로 적절한 queryable 함수를 실행하고 결과를 반환합니다.