Add example getchar async (on linux) polling queue loop.

parent 2877cab9
......@@ -35,7 +35,11 @@ clean:
$(foreach c, $(BINS), $(RM) $(c);)
$(RM) $(OBJS) $(HEADERS)
cleaner: clean
$(RM) $(wildcard deps/*/*.o)
$(RM) dukboot dukboot.exe makeheaders makeheaders.exe
test:
@./test.sh
.PHONY: test all clean install uninstall
.PHONY: test all clean install uninstall cleaner
function (o) {
var queue = []
function schedule (task) {
queue.push(task)
}
function read (end, cb) {
if (end) return cb(end)
var c = o.modules.getchar()
if (c === undefined) return schedule([read, end, cb])
if (c instanceof Error) return cb(c)
return schedule([cb, null, c])
}
function tick () {
if (queue.length === 0) throw Error("Queue complete.");
// Dequeue
var task = queue.shift();
// Run it
task[0].apply(null, task.slice(1))
return true
}
if (o.OpenMP.id === 0) {
var c
var chars = []
read(null, function next(end, data) {
if (end == true) return
if (end) throw end
o.modules.print(String.fromCharCode(data))
// schedule([read, null, next])
read(null, next)
})
var i = 0;
try {
while (true) {
o.modules.print("Tick count: " + i)
tick()
i++
}
} catch (e) {
o.modules.print(e)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment