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

erlang-processes

v2.2.2

Published

Erlang style processes in JavaScript

Downloads

6

Readme

Build Status

Experiment to reproduce Erlang style processes in browser. The api follows the one from Erlang. All are found on the ProcessSystem class

Documentation

https://elixirscript.github.io/processes/

Demo

https://elixirscript.github.io/processes/demo/

Usage

  • First, import the ProcessSystem create a new instance of one.

    const Processes = require('erlang-processes')
    let system = new Processes.default.ProcessSystem()
  • Now you can spawn processes using the system.

    A process will switch to other processes when yield is used and will run until it completes.

    var pid1 = system.spawn(function*() {
      while (true) {
        yield system.receive(function(value) {
          return console.log(value)
        })
    
        system.send(pid2, 'message from 1')
      }
    })
    
    system.register('Sally', pid1)
    
    var pid2 = system.spawn(function*() {
      while (true) {
        system.send('Sally', 'message from 2')
    
        yield system.receive(function(value) {
          return console.log(value)
        })
      }
    })

API

  • ProcessSystem

    • spawn(fun*) : pid - Starts a process represented by the given generator function
    • spawn(module, fun, args) : pid - Starts a process using the generator function from the specified module
    • link(pid) : void - links the current process with the process from the given pid
    • unlink(pid) : void - unlinks the current process from the process from the given pid
    • register(name, pid) : void - registers the given name to the pid
    • whereis(name) : pid - returns the pid registered by the given name or null if not registered
    • unregister(pid) : void - unregisters the names associated with the pid
    • registered() : Array - returns the liast of names that are registered
    • pid() : pid` - returns the current process's pid
    • pidof(obj) : pid - takes the input and tries to find the pid. Input can be a pid, Process, or name the pid is associated with
    • send(pid, msg) : msg - sends a message the the process represented by the pid
    • receive(fun, timeout = 0, timeoutFn = () => true) - Tells the current process to receive a message that the function can handle. If no match then the process is put in the suspended state until a message arrives or the timeout is reached. If the timeout is reached and no msg matches, then the timeoutFn is called
    • sleep(duration) - puts the current process to sleep
    • exit(reason) - terminates the current process with the given reason.
    • exit(pid, reason) - tells the process with the pid to exit with the given reason
    • error(reason) - terminates the current process with an error
    • process_flag(pid, flag, value) - Sets flags on the given process.
    • process_flag(flag, value) - Sets flags on the current process.
      • Note: the only flag respected is the Symbol.for("trap_exit") flag. If value is true, then exit signals from linked processes are turned into messages and sent to the current processes mailbox. If value is false, the exit is treated as normal and terminates the process. Setting it to true is useful for supervising processes.
    • put(key, value) - Adds a value to the current process's dictionary
    • get(key, default_value = null) - Gets a value from the current process's dictionary or the default if key not in dictionary
    • get_process_dict() - Gets the current process's dictionary
    • get_keys() - Gets all the keys from the current process's dictionary
    • get_keys(value) - Gets all the keys from the current process's dictionary with the given value
    • erase(key) - Removes the key and the associated value from the current process's dictionary
    • erase() - Removes all entries from the current process's dictionary
    • is_alive(pid) - Returns if the given pid is alive
    • make_ref() - Returns a unique reference
    • list() - Returns a list of all the pids
    • monitor(pid) - Monitors the given process
    • demonitor(ref) - Removes the monitor
  • ProcessSystem.run(fun, args, context = null) - A static generator function used to wrap a normal function or generator. If fun is a function, it returns the value, if it's a generator, then it delegates yielding to the generator.

References