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

messageworks

v0.1.16

Published

MessageWorks is a flexible framework for task orchestration, messaging, and workflow management across distributed systems. Simplify your processes with seamless communication and coordination.

Downloads

181

Readme

MessageWorks

MessageWorks is a flexible messaging framework for Node.js that handles message requests and responses in an efficient and scalable manner. It is designed to allow seamless communication between services, utilizing worker threads or external workers to handle message processing.

Features

  • Request-Response Messaging: Easily handle request/response patterns with worker threads or external workers.
  • Worker Thread Support: Use worker threads for background task processing.
  • Event-Driven: Built on an event-driven architecture to ensure efficient message handling.
  • Async Messaging: Supports asynchronous message handling, perfect for microservices and distributed systems.
  • TypeScript Support: Fully written in TypeScript, providing type safety and autocompletion.
  • Message Broadcasting: Supports broadcasting messages to multiple workers or services.

Installation

To install messageworks, you can use npm or yarn:

npm install messageworks

or

yarn add messageworks

Usage

Basic Usage Example

  1. TODO: Create a new messaging service:
import { MessagingService } from 'messageworks'

// Initialize the messaging service with a root messenger and callback function
const rootMessenger = '/root'
const rootCallback = (message) => {
  console.log('Message received in root callback:', message)
}

const messagingService = new MessagingService(rootMessenger, rootCallback)
  1. TODO: Send a message:
import { GeneralMessage } from 'messageworks'

const workerMessenger = '/root/echo'
const generalMessage = new GeneralMessage(workerMessenger)

// Send the message and handle response asynchronously
messagingService.sendMessage(requestMessage).then((response) => {
  console.log('Received response:', response)
})

Handling Worker Responses

TODO: If you're working with worker threads, you can add workers to the messaging service to handle incoming requests and send responses.

const workerScript = createResponseWorkerScript(workerMessenger)
const worker = new WorkerMock(URL.createObjectURL(new Blob([workerScript])))

// Add worker to the messaging service
messagingService.addWorker(workerMessenger, worker)

// Send a request and wait for the response
const request = new ConcreteRequestMessageMock(workerMessenger)
messagingService.sendMessage(request).then((response) => {
  console.log('Worker Response:', response)
})

API

MessagingService

sendMessage<T>(message: GeneralMessage<T>, worker?: Worker): Promise<ResponseMessage<T> | null>

  • message: The message to be sent. This could be a request or response message.
  • worker (optional): The worker to send the message to. If omitted, the message will be sent to the appropriate worker.
  • returns: A promise that resolves to a response message if the message is a request; otherwise, resolves to null.

WorkerMock

TODO: A mock worker implementation for testing purposes.

const worker = new WorkerMock(URL.createObjectURL(new Blob([workerScript])));

Contributing

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Make your changes.
  4. Run tests (npm test).
  5. Commit your changes (git commit -am 'Add new feature').
  6. Push to the branch (git push origin feature-branch).
  7. Open a pull request.

License

Apache License 2.0

Copyright 2024 Bahay Labs, LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.