Skip to content

francesco-bracchi/cojs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cojs

Build Status

This Library is heavily inspired by

clojure.core.async.

and the Haskell mvars;

This library doesn't make use generators or promises, but a walker is implemented, that rewrites fork blocks, thanks to sweetjs macro system

Install

Prerequisites

Install sweetjs

npm install -g sweetjs

Install

npm install cojs

Use

sjs -m cojs/macros <file>.js

example

var mvar = require('cojs/mvar');

var ch = mvar(),
    m = 80000,
    n = 0;

fork {
  while (true) {
    var v <~ ch;
    console.log ('received 1: ' + v);
  }
}

fork { 
  while (true) {
    var v <~ ch;
    console.log ('received 2: ' + v);
  }
}

fork {
  while (n < m) {
    ch ~> n;
    console.log ('sent: ' + n);
    n++;
  } 
} 

Some more examples are implemented in the /examples dir

modules

cojs/mvar

cojs/chan

cojs/throwErr

wrapper around a channel that throws an error if the returned value is an instanceof Error

tasks

cojs/tasks/timeout

cojs/tasks/split

cojs/tasks/slurp

TODO

features to be completed

  1. enable switch statement support in action expressions
  2. enable continue/break in action expressions
  3. test, test, test

About

clojure.core.async like statements for javascript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published