First call!
This commit is contained in:
parent
9668e95495
commit
5eb836ad32
|
@ -6,9 +6,10 @@
|
||||||
|
|
||||||
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
|
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
|
||||||
<link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet">
|
<link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet">
|
||||||
<script src="bootstrap/js/bootstrap.min.js"></script>
|
<!-- <script src="bootstrap/js/bootstrap.min.js"></script> -->
|
||||||
|
|
||||||
<script src="marketplace.js"></script>
|
<script src="marketplace.js"></script>
|
||||||
|
<script src="index.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
var g = new Ground(function () {
|
||||||
|
console.log('here');
|
||||||
|
World.spawn({
|
||||||
|
step: function () { console.log('step'); },
|
||||||
|
boot: function () {
|
||||||
|
console.log('boot');
|
||||||
|
World.updateRoutes([sub(__), sub(__, 1)]);
|
||||||
|
World.send({msg: 'hello outer world'}, 1);
|
||||||
|
World.send({msg: 'hello inner world'}, 0);
|
||||||
|
},
|
||||||
|
handleEvent: function (e) {
|
||||||
|
console.log('handleEvent: ' + JSON.stringify(e));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
g.startStepping();
|
|
@ -166,14 +166,15 @@ function filterEvent(e, routes) {
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/* Configurations */
|
/* Configurations */
|
||||||
|
|
||||||
function World(bootActions) {
|
function World(bootFn) {
|
||||||
this.nextPid = 0;
|
this.nextPid = 0;
|
||||||
this.eventQueue = [];
|
this.eventQueue = [];
|
||||||
this.processTable = {};
|
this.processTable = {};
|
||||||
this.downwardRoutes = [];
|
this.downwardRoutes = [];
|
||||||
this.processActions = [];
|
this.processActions = [];
|
||||||
this.activePid = null;
|
this.activePid = null;
|
||||||
this.enqueueActions(-1, bootActions);
|
this.stepperId = null;
|
||||||
|
this.asChild(-1, bootFn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Class state / methods */
|
/* Class state / methods */
|
||||||
|
@ -192,6 +193,10 @@ World.spawn = function (behavior, initialRoutes) {
|
||||||
World.current.enqueueAction(spawn(behavior, initialRoutes));
|
World.current.enqueueAction(spawn(behavior, initialRoutes));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
World.wrap = function (f) {
|
||||||
|
return World.current.wrap(f);
|
||||||
|
};
|
||||||
|
|
||||||
/* Instance methods */
|
/* Instance methods */
|
||||||
|
|
||||||
World.prototype.enqueueAction = function (action) {
|
World.prototype.enqueueAction = function (action) {
|
||||||
|
@ -214,6 +219,24 @@ World.prototype.step = function () {
|
||||||
return this.stepChildren() || !this.isQuiescent();
|
return this.stepChildren() || !this.isQuiescent();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
World.prototype.startStepping = function () {
|
||||||
|
var self = this;
|
||||||
|
if (this.stepperId) return;
|
||||||
|
if (this.step()) {
|
||||||
|
this.stepperId = setTimeout(function () {
|
||||||
|
self.stepperId = null;
|
||||||
|
self.startStepping();
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
World.prototype.stopStepping = function () {
|
||||||
|
if (this.stepperId) {
|
||||||
|
clearTimeout(this.stepperId);
|
||||||
|
this.stepperId = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
World.prototype.asChild = function (pid, f) {
|
World.prototype.asChild = function (pid, f) {
|
||||||
var oldWorld = World.current;
|
var oldWorld = World.current;
|
||||||
var result = null;
|
var result = null;
|
||||||
|
@ -229,6 +252,15 @@ World.prototype.asChild = function (pid, f) {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
World.prototype.wrap = function (f) {
|
||||||
|
var savedWorld = this;
|
||||||
|
var savedPid = this.activePid;
|
||||||
|
return function () {
|
||||||
|
var actuals = arguments;
|
||||||
|
return savedWorld.asChild(savedPid, function () { return f.apply(null, actuals) });
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
World.prototype.kill = function (pid, exn) {
|
World.prototype.kill = function (pid, exn) {
|
||||||
console.log("Killed process " + pid + (exn ? " with reason " + exn.message : ""));
|
console.log("Killed process " + pid + (exn ? " with reason " + exn.message : ""));
|
||||||
delete this.processTable[pid];
|
delete this.processTable[pid];
|
||||||
|
@ -240,7 +272,7 @@ World.prototype.stepChildren = function () {
|
||||||
for (var pid in this.processTable) {
|
for (var pid in this.processTable) {
|
||||||
var p = this.processTable[pid];
|
var p = this.processTable[pid];
|
||||||
if (p.behavior.step /* exists, haven't called it yet */) {
|
if (p.behavior.step /* exists, haven't called it yet */) {
|
||||||
var childBusy = this.asChild(pid, function () { p.behavior.step() });
|
var childBusy = this.asChild(pid, function () { return p.behavior.step() });
|
||||||
someChildBusy = someChildBusy || childBusy;
|
someChildBusy = someChildBusy || childBusy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,6 +330,7 @@ World.prototype.aggregateRoutes = function (base) {
|
||||||
acc.push(p.routes[i]);
|
acc.push(p.routes[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return acc;
|
||||||
};
|
};
|
||||||
|
|
||||||
World.prototype.issueRoutingUpdate = function () {
|
World.prototype.issueRoutingUpdate = function () {
|
||||||
|
@ -331,9 +364,46 @@ World.prototype.handleEvent = function (e) {
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/* Ground interface */
|
/* Ground interface */
|
||||||
|
|
||||||
function Ground(bootActions) {
|
function Ground(bootFn) {
|
||||||
this.world = new World(bootActions);
|
var self = this;
|
||||||
this.subscriptions = {};
|
this.stepperId = null;
|
||||||
|
this.wrap(function () {
|
||||||
|
self.world = new World(bootFn);
|
||||||
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
// HERE: Ground.prototype.
|
Ground.prototype.wrap = function (f) {
|
||||||
|
var self = this;
|
||||||
|
return function () {
|
||||||
|
var oldWorld = World.current;
|
||||||
|
var result = null;
|
||||||
|
World.current = self;
|
||||||
|
try {
|
||||||
|
result = f();
|
||||||
|
} catch (e) {
|
||||||
|
World.current = oldWorld;
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
World.current = oldWorld;
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
Ground.prototype.step = function () {
|
||||||
|
var self = this;
|
||||||
|
return this.wrap(function () {
|
||||||
|
return self.world.step();
|
||||||
|
})();
|
||||||
|
};
|
||||||
|
|
||||||
|
Ground.prototype.startStepping = World.prototype.startStepping;
|
||||||
|
Ground.prototype.stopStepping = World.prototype.stopStepping;
|
||||||
|
|
||||||
|
Ground.prototype.enqueueAction = function (action) {
|
||||||
|
if (action.type === 'routes') {
|
||||||
|
// Ignore it. These are generated outside user control so it
|
||||||
|
// shouldn't be an error.
|
||||||
|
} else {
|
||||||
|
console.error("You have sent a message into the outer void.", action);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue