Debian Codegraph @

src/host-web/webchuck/examples/globals6/index.html

raw symbols SCIP
1 <!doctype html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8">
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <title>ChucK + JS => ChucKScript</title>
7 <link rel="stylesheet" href="../../css/editor.css">
8 </head>
9 <body onresize="chuckEditor.resize();">
10 <div>
11 <div id="program">// Globals 6: global Events
12 global Event metro;
13 global Event oneAtATime;
14 global Event allAtOnce;
15
16 fun void wait1()
17 {
18 oneAtATime => now;
19 <<< "signaled!", now / second >>>;
20 }
21 spork ~ wait1();
22 spork ~ wait1();
23 fun void wait2()
24 {
25 allAtOnce => now;
26 <<< "broadcasted!", now / second >>>;
27 }
28 spork ~ wait2();
29 spork ~ wait2();
30
31 fun void RideTheMetro()
32 {
33 while( true )
34 {
35 0.348::second => now;
36 metro.broadcast();
37 }
38 }
39 spork ~ RideTheMetro();
40
41 while( true )
42 {
43 1::second => now;
44 }
45
46 </div>
47 </div>
48 <div class="buttons">
49 <button class="chuckButton" id="startChuck" disabled="disabled">Start ChucK</button>
50 <button class="chuckButton" id="compileButton" disabled="disabled">Compile and Run</button>
51 <button class="chuckButton" id="replaceButton" disabled="disabled">Replace</button>
52 <button class="chuckButton" id="removeButton" disabled="disabled">Remove</button>
53 <button class="chuckButton" id="clearButton" disabled="disabled">Clear VM and Globals</button>
54 <button class="chuckButton" id="micButton" disabled="disabled">Enable Microphone</button>
55 <button class="chuckButton" id="fileFormButton">Show File Uploader</button>
56 </div>
57 <div id="fileForm" class="hidden">
58 <p>File name to use in ChucK: <input type="text" id="uploadFilename"></p>
59 <p>Local file to upload: <input type="file" id="uploadFile" name="uploadFile"></p>
60 <p><button class="chuckButton" id="fileButton" disabled="disabled">Upload File to Virtual File System</button></p>
61 </div>
62 <div>
63 <textarea id="output"></textarea>
64 <div id="shreds">
65 <table id="shredstable">
66 <col width="60px">
67 <col width="1*">
68 <col width="50px">
69 <col width="60px">
70 <tr><th>shred</th><th>code</th><th>time</th><th>remove</th>
71 </table>
72 </div>
73 <div class="clearfix"></div>
74 </div>
75 <script type="text/javascript" src="../../js/ace-min-noconflict/ace.js" charset="utf-8"></script>
76 <script type="text/javascript" src="../../js/editor.js"></script>
77 <script type="text/javascript" src="../../js/defer.js"></script>
78 <script>
79 // override
80 var whereIsChuck = "../../js";
81 </script>
82 <script type="text/javascript" src="../../js/webchuck_host.js"></script>
83 <script type="text/javascript" src="../../js/host.js"></script>
84 <script>
85 theChuckReady.then( function()
86 {
87 // compile it for this test without waiting for the user to click button
88 // just to make sure the global Event exists
89 theChuck.runCode( "global Event metro; global Event oneAtATime; global Event allAtOnce;" ).then( function( shred )
90 {
91 // so we can do this after
92 var times = 5;
93 var metroStopID = theChuck.startListeningForEvent( "metro", function() {
94 chuckPrint( "I am listening to metro " + times + " more times" );
95 times--;
96 if( times <= 0 )
97 {
98 theChuck.stopListeningForEvent( "metro", metroStopID );
99 }
100 } );
101
102
103 theChuck.listenForEventOnce( "metro", function() {
104 chuckPrint( "I'm a metro listener that gets called only once. " );
105 });
106
107 chuckPrint( "Make sure you run the code within 5 seconds!" );
108 setTimeout( function () {
109 theChuck.signalEvent( "oneAtATime" );
110 theChuck.broadcastEvent( "allAtOnce" );
111 setTimeout( function() {
112 theChuck.signalEvent( "oneAtATime" );
113 theChuck.broadcastEvent( "allAtOnce" ); // nothing should happen in response to this one
114 }, 1000);
115 }, 5000 );
116 });
117 });
118 </script>
119 </body>
120 </html>
121
122