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

actrix

v4.1.0

Published

Actrix is actor system library for NodeJS/Browser. While traditionally actors are about concurrency and paralellism of a highly scalable and/or distributed applications, Actrix is mainly designed to help developers to write code which deals well with "con

Downloads

27

Readme

Actrix

Actrix is actor system library for NodeJS/Browser. While traditionally actors are about concurrency and paralellism of a highly scalable and/or distributed applications, Actrix is mainly designed to help developers to write code which deals well with "concurrency" (read: asynchronousity) without forcing them to completely change the coding paradigm.

Getting Started

Follow this instruction to get started with Actrix.

Installing

To use Actrix on your project, install it using npm or yarn.

yarn add actrix

or

npm install actrix

Concepts

Actor is a unit of concurrency where you can define some behavior, similar to an oobject. However, unlike object, you don't invoke a method in actor but you can send messages to it. The messages are scheduled asynchronously, leaving the execution flow up to the actor. Actor process its messages in sequential, one-at-a-time fashion. This makes reasoning of the processing code much simpler.

API

Defining Actors

Follow the following template to define an actor.

// The interface to "talk" to the actor
type YourActorAPI = {
    yourMethodName: (payload: PayloadType) => Promise<void>; // the exposed "method". They should always be in form of function which returns Promise/CancellablePromise
};

// Define a class which extends Actor<T>. The `T` parameter is only needed when you want to pass a value during initialization.
class YourActor extends Actor<number> implements YourActorAPI {

    yourMethodName = async (payload: PayloadType) => {
        // Implementation for handling messages of this type
        ...
    };

    // Optional, only needed if `T` is defined. This will be triggered when the actor is instantiated
    protected init(initialCounter: number) {
        // Implementation
        ...
    }
}

Create Actor Systems

const actorSystem = new ActorSystem(name?);

Create a new actor system with a specified string as the name. When name is not specified, it will randomly create a random value for it.

Create Actors

const actorRef = actorSystem.createActor(options);

Create a new actor inside the actorSystem. The options parameter are as follow:

name: (Required) A string representing the name of your actor instance actorClass: (Required) The class definition of the actor paramOptions: (Optional) The value you want to pass to the actor during initialization. Only needed when you define the type generic T as explained in the actor template strategies: (Optional) List of strategies you want to use for your actor. At the moment it has only one possible value: IgnoreOlderMessageWithTheSameType which can be used to optimize your actor to only execute the most recent message of the same type

Sending a Message to Actors

From an Actor

this.sendTo(actorRef).yourMethodName(payload?);

actorRef: (Required) the target actorRef where we send the message to payload: (As defined by the target actor) payload of the message as defined by the target actor

this.sendTo<TargetActorAPI>(address).yourMethodName(payload?);

address: (Required) the target address where we send the message to, if TargetActorAPI is not specified then there will be no compile-time check payload: (As defined by the target actor) payload of the message as defined by the target actor

From Everywhere Else

actorRef.send(sender?).yourMethodName(payload?);

This is the typical way to send a message to an actor from outside of actors. Sender parameter is optional, but if you need to use it, better to just use the previous API.

sender: (Optional) the address of the sender payload: (As defined by the target actor) payload of the message as defined by the target actor

Replying to Messages

const senderRef = this.context.senderRef;
this.sendTo(senderRef).yourMethodName(payload?);

Getting Address of Actors

const address = actorRef.address;

Examples

See actrix-example for examples.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Ismail Habib Muhammad - Initial work

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details