Skip to content

Instantly share code, notes, and snippets.

@samuelgoto
Last active November 28, 2017 20:13
Show Gist options
  • Save samuelgoto/26c50ae29d1b2fc10419c48707ff05a6 to your computer and use it in GitHub Desktop.
Save samuelgoto/26c50ae29d1b2fc10419c48707ff05a6 to your computer and use it in GitHub Desktop.

Message Passing

const api = await remote {
  import foo from 'foo.js';

  export class A {
    func() {
      foo();
      return 42;
    }
  }
};

const a = new api.A();
a.func() == 42;
void  main(void) {
 pid_t  pid;

 pid = fork();
 if (pid == 0) 
   ChildProcess();
 else 
   ParentProcess();
}
import java.rmi.*;  
import java.rmi.server.*;  

public interface Adder extends Remote {  
  public int add(int x,int y) throws RemoteException;  
}

public class AdderRemote extends UnicastRemoteObject implements Adder {  
  AdderRemote() throws RemoteException{  
    super();  
  }

  public int add(int x,int y){
    return x+y
    }
  } 
}

And client:

import java.rmi.*;  
import java.rmi.registry.*;  
public class MyServer { 
public static void main(String args[]) {  
  try {  
    Adder stub = new AdderRemote();  
    Naming.rebind("rmi://localhost:5000/sonoo", stub);  
  } catch(Exception e) {
    System.out.println(e);
  }  
}  

Object Capabilities / E

Stubby

Mojo

Shared Memory

new Thread(function() { console.log("Hello, threads!"); });
@samuelgoto
Copy link
Author

samuelgoto commented Nov 28, 2017

Not entirely sure if this is possible/desirable, but maybe, really maybe, with block params one could enable tasklets to be written with some really really hacky / underperforming code:

const {A, func} = await remote {
  import foo from 'foo.js';

  export class A {
    func() {
      foo();
      return 42;
    }
  }
};

const a = new A();
func() == 42;

Something along the lines of:

async function remote (block) {
  // gets the source code of the block
  let code = block.toString();

  // NOTE(goto): note sure if this is the right way to do service worker things.
  navigator.serviceWorker.register("/worker.js").then(function() {
    self.addEventListener("fetch", function(e) {
      e.respondWith(code);
    });
  });

  let worker = new Worker("/worker.js");
  // do the tasklet proxying magic here
  return tasklet_magic;
}

So that the original gets translated to:

const {A, func} = await remote(function() {
  import foo from 'foo.js';

  export class A {
    func() {
      foo();
      return 42;
    }
  }
});

const a = new A();
func() == 42;

I'd be surprised if this ever worked, but kinda of an interesting thought.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment