diff options
Diffstat (limited to 'shell/samples/os.fork.js')
-rw-r--r-- | shell/samples/os.fork.js | 88 |
1 files changed, 62 insertions, 26 deletions
diff --git a/shell/samples/os.fork.js b/shell/samples/os.fork.js index debdebcc..5833fdc4 100644 --- a/shell/samples/os.fork.js +++ b/shell/samples/os.fork.js @@ -1,30 +1,66 @@ -igt.os.fork('hello', print).wait(); - -igt.os.fork([ {delay: 1, msg:'goodbye' }, {delay:0, msg:'world'} ], - function(x) { igt.os.sleep(x.delay); print(x.msg) }).wait(); - -var job = igt.os.fork('', function(x) { igt.os.exit(1); igt.os.sleep(999); }); -print('Exitcode = ' + job.wait()); - -job = igt.os.fork(); -if (job) { - print("Parent shall wait for its child!"); - job.wait(); -} else { - print("The child wants to play!"); - for (var x = 0; x < 10; x++) { - print("Play " + x); - igt.os.sleep(0.1); +import console from '../lib/console'; +import { range } from '../lib/util'; + +const { fork, sleep, exit } = igt.os; + +{ + fork('hello', console.log).wait(); +} + +{ + const children = [ + { + delay: 1, + msg: 'goodbye', + }, + { + delay: 0, + msg: 'world', + }, + ]; + + const childrenMain = ({ delay, msg }) => { + sleep(delay); + console.log(msg); + }; + + fork(children, childrenMain).wait(); + + { + const job = fork('', () => { + exit(1); + sleep(999); + }); + console.log('Exitcode = %d', job.wait()); } - print("Tired now!"); - igt.os.exit(0); } -print("Only parents allowed after children sleep, exitcode:", job.result); -job = igt.os.fork(); -if (job) { - print("No Mr Bond, I expect you to", job.wait()); -} else { - badwolf(); +{ + const job = fork(); + if (job) { + console.log('Parent shall wait for its child!'); + job.wait(); + } else { + console.log('The child wants to play!'); + for (const i of range(0, 10)) { + console.log('Play ' + i); + sleep(0.1); + } + console.log('Tired now!'); + exit(0); + } + console.log( + 'Only parents allowed after children sleep, exitcode: %d', + job.result, + ); +} + +{ + const job = fork(); + if (job) { + console.log('No Mr Bond, I expect you to', job.wait()); + } else { + badwolf(); + } + console.log('Onwards, all by myself.'); } -print("Onwards, all by myself."); |