Wednesday, 5 April 2017

sharing memory for static class in typescript

I'm wondering is it possible to implement sort of poor man's pub-sub system using following:

Say I have a static class (all static varible and methods)

class Cars {
  static myCars: Array<string>
  static addCar(newCar: string) {
     this.myCars.append(newCar)
  }
  static removeOneCar() {
     // remove the  last car from this.myCars array
  }
}

and there's a method is to add item into this class's variable, say

addCar in this case.

And then I have a web server importing this class, adding cars when requests come.

And I have another process which import this static class, and calls "removeOneCar" every 1 second.

My question is, they don't seem to share the same memory space, since I'm running my server as

node ./built/server.js and running the consumer as

node ./built/consume.js

How to make them share memory? Is it even possible?



via eddie.xie

No comments:

Post a Comment