2016-03-21 01:01:17 +00:00
|
|
|
// bin/syndicatec compiler/demo-filesystem.js | node
|
|
|
|
|
2016-08-07 19:33:09 +00:00
|
|
|
// Good output:
|
|
|
|
//
|
|
|
|
// At least one reader exists for: hello.txt
|
|
|
|
// hello.txt has content undefined
|
|
|
|
// hello.txt has content "a"
|
|
|
|
// hello.txt has content undefined
|
|
|
|
// hello.txt has content "c"
|
|
|
|
// hello.txt has content "quit demo"
|
|
|
|
// The hello.txt file contained 'quit demo', so we will quit
|
|
|
|
// second observer sees that hello.txt content is "final contents"
|
|
|
|
// No remaining readers exist for: hello.txt
|
|
|
|
|
2016-03-21 01:01:17 +00:00
|
|
|
var Syndicate = require('./src/main.js');
|
|
|
|
|
|
|
|
assertion type file(name, content) = "file";
|
2016-05-12 01:05:40 +00:00
|
|
|
message type saveFile(name, content) = "save";
|
|
|
|
message type deleteFile(name) = "delete";
|
2016-03-21 01:01:17 +00:00
|
|
|
|
2016-04-07 07:42:54 +00:00
|
|
|
ground dataspace {
|
2016-03-21 01:01:17 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// The file system actor
|
|
|
|
|
2017-02-16 19:38:56 +00:00
|
|
|
spawn {
|
2016-03-21 01:01:17 +00:00
|
|
|
this.files = {};
|
2016-08-25 12:12:32 +00:00
|
|
|
during Syndicate.observe(file($name, _)) {
|
|
|
|
on start {
|
|
|
|
console.log("At least one reader exists for:", name);
|
2016-03-21 01:01:17 +00:00
|
|
|
}
|
2016-08-25 12:12:32 +00:00
|
|
|
assert file(name, field this.files[name]);
|
|
|
|
on stop {
|
|
|
|
console.log("No remaining readers exist for:", name);
|
2016-03-21 01:01:17 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-25 12:12:32 +00:00
|
|
|
on message saveFile($name, $newcontent) {
|
|
|
|
field this.files[name] = newcontent;
|
|
|
|
}
|
|
|
|
on message deleteFile($name) {
|
|
|
|
delete field this.files[name];
|
|
|
|
}
|
2016-03-21 01:01:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// A simple demo client of the file system
|
|
|
|
|
2017-02-16 19:38:56 +00:00
|
|
|
spawn {
|
2016-08-25 12:12:32 +00:00
|
|
|
on asserted file("hello.txt", $content) {
|
|
|
|
console.log("hello.txt has content", JSON.stringify(content));
|
2016-03-21 01:01:17 +00:00
|
|
|
}
|
|
|
|
|
2016-08-25 12:12:32 +00:00
|
|
|
stop on asserted file("hello.txt", "quit demo") {
|
|
|
|
console.log("The hello.txt file contained 'quit demo', so we will quit");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-16 19:38:56 +00:00
|
|
|
spawn {
|
2016-08-25 12:12:32 +00:00
|
|
|
stop on asserted Syndicate.observe(saveFile(_, _)) {
|
|
|
|
:: saveFile("hello.txt", "a");
|
|
|
|
:: deleteFile("hello.txt");
|
|
|
|
:: saveFile("hello.txt", "c");
|
|
|
|
:: saveFile("hello.txt", "quit demo");
|
|
|
|
:: saveFile("hello.txt", "final contents");
|
2017-02-16 19:38:56 +00:00
|
|
|
spawn {
|
2016-08-25 12:12:32 +00:00
|
|
|
stop on asserted file("hello.txt", $content) {
|
|
|
|
console.log("second observer sees that hello.txt content is",
|
|
|
|
JSON.stringify(content));
|
2016-03-21 01:01:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|