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

@darlean/core

v2.0.0-alpha.27

Published

Darlean core functionality for creating applications that define, expose and host actors

Downloads

47

Readme

Introduction

The @darlean/core package provides the functionality that is required to create an application that hosts Darlean actors.

  • For information on how to create actors and actor suites, see the @darlean/base package (GitLab|NPM).

Installation

$ npm install @darlean/core

Usage

Use as a server application

The standard usage of @darlean/core as a server application is as follows:

const builder = new ConfigRunnerBuilder();
builder.registerSuite( createYourSuite() );
const runner = builder.build();
await runner.run();

The first line creates a new ConfigRunnerBuilder instance. A config-runner-builder is a class that builds an ActorRunner from the configuration that is present as JSON/JSON5 file on disk, that is present as command-line arguments and/or that is present via environment variables. Click here for documentation about configuring Darlean and all the configuration options that are available.

The second line registers the actor suite(s) that contain the actors that should be hosted by the application. This can be custom-made actor suites that contain project-specific functionality, or it can be standard (out-of-the-box) actor suites provided by Darlean or other parties (including the @darlean/runtime-suite (GitLab|NPM)) which is a bundle that contains a minimal set of suites that together provide runtime functionality).

The third line uses the configuration options and the registered suites to build an ActorRunner instance.

The last line actually starts the runner and waits until it is finished, which is when the application is killed, when the run file is deleted or when application code calls await runner.stop().

Use as a client application

Client applications that may want to interact with Darlean actors may not want the runner to wait until the client application is explicitly stopped. They may want the application to stop immediately when their work is ready.

For that, replace the last line await runner.run() with the follwing block:

await runner.start();
try {
  // Do your work here
} finally {
  await runner.stop();
}

Access to actors

A client application can get access to remote actors (and invoke action methods on them) by means of an IPortal that can be obtained via ActorRunner.getPortal():

const actor = runner.getPortal().retrieve<IActorType>('ActorType', ['the', 'id', 'of', 'the', 'actor']);
const result = await actor.doSomething(arg1, arg2);

In this snippet, actor is a proxy (stub) with interface IActorType. In this snippet, we assume that IActorType has a method doSomething(arg1, arg2), which is why the second like works. The retrieve expects the actor type (in this example: 'ActorType'), and the Id (which is a string[]).

Typed actors

When application code needs access to multiple actors of the same type, it is recommended to use an ITypedPortal:

const typedPortal = runner.getPortal().typed<IActorType>('ActorType');
const oneActor = typedPortal.retrieve(['id1']);
const anotherActor = typedPortal.retrieve(['id2']);

Elaborative example

The usage of @darlean/core is further illustrated by means of an elaborative example of a minimalistic but real, working distributed application.

Configuration

Darlean apps can be configured by means of JSON/JSON5 files, command-line arguments and environment variables.

More information about how to configure Darlean can be found here.

See also

  • Package @darlean/base (GitLab|NPM) which explains how to create actors and actor suites
  • A minimalistic example application that uses the above mentioned echo actor.
  • The Darlean Tutorial in which we illustrate step by step how to build a real distributed oracle that answers questions like 'How warm is it tomorrow?' and 'What is the price of milk?'.
  • The Darlean Documentation on our website.
  • The API Documentation for @darlean/core.