Code Monkey home page Code Monkey logo

processes's People

Contributors

bryanjos avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

processes's Issues

Can make a test code run

Dear maintainer of the this project, I'm trying to learn how to use this code by translate the following code into process.js

-module(counter_server).
-export([start/1, add/1, get/1]).


start(State) ->
    spawn(fun() -> loop(State) end).

add(Pid) ->
    cast(Pid, {add}).

get(Pid) ->
    call(Pid, {get}).

call(Pid, {Request}) ->
    Pid ! {Request, self()},
    receive
        Response -> Response
    end.

cast(Pid, {Request}) ->
    Pid ! {Request}.

loop(State) ->
    receive
        {add} ->
            loop(State + 1);
        {get, From} ->
            From ! State,
            loop(State)
    end.

the following is my attempt

const { ProcessSystem } = require("./process.js")

const system = new ProcessSystem()

main()

function main() {
    const p = start(10)
    console.log(get(p)) // undefined
}


function start(state) {
    return system.spawn(function*() {
        yield* loop(state)
    })
}

function add(pid) {
    cast(pid, ["add"])
}

function get(pid) {
    const G = ProcessSystem.run(call, [pid, ["get"]], this)
}

function* call(pid, [request]) {
    console.log("send") // never get called
    let response
    system.send([request, system.pid()])
    yield system.receive(response1 => response = response1)
    return response

}
function cast(pid, [request]) {
    system.send([request])
}

function* loop(state) {
    system.receive(([mesg, from]) => {
        console.log(mesg, from)
        if(mesg === "add" && !from)
            yield* loop(state + 1)
        else if(mesg === "get" && from) {
            console.log(from)
            system.send(from, state)
            yield* loop(state)
        }
    })
}

the first comment line log undefined, the second comment line never execute which I think where the problem is, Could you help a look where I did wrong

======= version 2

const { ProcessSystem } = require("./process.js")

const system = new ProcessSystem()

main()

function main() {
    const p = start(10)
    const g = get(p)
    const result = g.next()
    console.log(result)
}


function start(state) {
    return system.spawn(function*() {
        yield* loop(state)
    })
}

function add(pid) {
    cast(pid, ["add"])
}

function* get(pid) {
    yield* ProcessSystem.run(call, [pid, ["get"]], null)
}

function* call(pid, [request]) {
    let response
    system.send(pid, [request, system.pid()])
    console.log("mark1")
    yield system.receive(response1 => {
        response = response1
        console.log("mark2")
    })
    console.log("mark3")
    return response
}


function cast(pid, [request]) {
    system.send([request])
}
function* loop(state) {
    system.receive(([mesg, from]) => {
        console.log("mark4")
        if(mesg === "add" && !from)
            yield* loop(state + 1)
        else if(mesg === "get" && from) {
            console.log(from)
            system.send(from, state)
            yield* loop(state)
        }
    })
}
mark1
{ value: [ Symbol(receive), [Function], null, [Function: timeoutFn] ],
  done: false }

Fair TaskQueue

Right now the TaskQueue is FIFO. It would be better to implement a fair task queue implementation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.