{"id":19816249,"url":"https://github.com/elixirscript/processes","last_synced_at":"2025-05-01T10:32:29.824Z","repository":{"id":57226666,"uuid":"43971646","full_name":"elixirscript/processes","owner":"elixirscript","description":"Erlang style processes in JavaScript","archived":false,"fork":false,"pushed_at":"2019-08-13T14:05:13.000Z","size":958,"stargazers_count":55,"open_issues_count":0,"forks_count":4,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-10-13T11:40:04.770Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://elixirscript.github.io/processes/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elixirscript.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-09T17:59:15.000Z","updated_at":"2024-09-04T13:41:05.000Z","dependencies_parsed_at":"2022-08-22T12:20:45.431Z","dependency_job_id":null,"html_url":"https://github.com/elixirscript/processes","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixirscript%2Fprocesses","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixirscript%2Fprocesses/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixirscript%2Fprocesses/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixirscript%2Fprocesses/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elixirscript","download_url":"https://codeload.github.com/elixirscript/processes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224253480,"owners_count":17280934,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T10:08:48.468Z","updated_at":"2024-11-12T10:08:48.534Z","avatar_url":"https://github.com/elixirscript.png","language":"JavaScript","readme":"[![Build Status](https://travis-ci.org/elixirscript/processes.svg?branch=master)](https://travis-ci.org/elixirscript/processes)\n\nExperiment to reproduce Erlang style processes in browser. The api follows the one from Erlang. All are found on the `ProcessSystem` class\n\n#### Documentation\n\nhttps://elixirscript.github.io/processes/\n\n#### Demo\n\nhttps://elixirscript.github.io/processes/demo/\n\n#### Usage\n\n- First, import the ProcessSystem create a new instance of one.\n\n  ```javascript\n  const Processes = require('erlang-processes')\n  let system = new Processes.default.ProcessSystem()\n  ```\n\n- Now you can spawn processes using the system.\n\n  A process will switch to other processes when yield is used and will run until it completes.\n\n  ```javascript\n  var pid1 = system.spawn(function*() {\n    while (true) {\n      yield system.receive(function(value) {\n        return console.log(value)\n      })\n\n      system.send(pid2, 'message from 1')\n    }\n  })\n\n  system.register('Sally', pid1)\n\n  var pid2 = system.spawn(function*() {\n    while (true) {\n      system.send('Sally', 'message from 2')\n\n      yield system.receive(function(value) {\n        return console.log(value)\n      })\n    }\n  })\n  ```\n\n### API\n\n- ProcessSystem\n\n  - `spawn(fun*) : pid` - Starts a process represented by the given generator function\n  - `spawn(module, fun, args) : pid` - Starts a process using the generator function from the specified module\n  - `link(pid) : void` - links the current process with the process from the given pid\n  - `unlink(pid) : void` - unlinks the current process from the process from the given pid\n  - `register(name, pid) : void` - registers the given name to the pid\n  - `whereis(name) : pid` - returns the pid registered by the given name or null if not registered\n  - `unregister(pid) : void` - unregisters the names associated with the pid\n  - `registered() : Array` - returns the liast of names that are registered\n  - `pid()` : pid` - returns the current process's pid\n  - `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\n  - `send(pid, msg) : msg` - sends a message the the process represented by the pid\n  - `receive(fun, timeout = 0, timeoutFn = () =\u003e 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\n  - `sleep(duration)` - puts the current process to sleep\n  - `exit(reason)` - terminates the current process with the given reason.\n  - `exit(pid, reason)` - tells the process with the pid to exit with the given reason\n  - `error(reason)` - terminates the current process with an error\n  - `process_flag(pid, flag, value)` - Sets flags on the given process.\n  - `process_flag(flag, value)` - Sets flags on the current process.\n    - 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.\n  - `put(key, value)` - Adds a value to the current process's dictionary\n  - `get(key, default_value = null)` - Gets a value from the current process's dictionary or the default if key not in dictionary\n  - `get_process_dict()` - Gets the current process's dictionary\n  - `get_keys()` - Gets all the keys from the current process's dictionary\n  - `get_keys(value)` - Gets all the keys from the current process's dictionary with the given value\n  - `erase(key)` - Removes the key and the associated value from the current process's dictionary\n  - `erase()` - Removes all entries from the current process's dictionary\n  - `is_alive(pid)` - Returns if the given pid is alive\n  - `make_ref()` - Returns a unique reference\n  - `list()` - Returns a list of all the pids\n  - `monitor(pid)` - Monitors the given process\n  - `demonitor(ref)` - Removes the monitor\n\n- `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.\n\n## References\n\n- [Er.js](https://github.com/orph/erjs)\n- [Erlang Processes](http://erlang.org/doc/reference_manual/processes.html)\n- [ES6 Generators Deliver Go Style Concurrency](http://swannodette.github.io/2013/08/24/es6-generators-and-csp)\n- [Red and Green Callbacks](http://joearms.github.io/2013/04/02/Red-and-Green-Callbacks.html)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixirscript%2Fprocesses","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felixirscript%2Fprocesses","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixirscript%2Fprocesses/lists"}