File tree Expand file tree Collapse file tree 4 files changed +130
-0
lines changed
Expand file tree Collapse file tree 4 files changed +130
-0
lines changed Original file line number Diff line number Diff line change 1+ This examples directory shows some examples written in [ Hack] ( https://hacklang.org ) .
2+
3+ ### Requirements :
4+
5+ - [ HHVM] ( https://github.com/facebook/hhvm ) 3.30+
6+ - [ HSL ( Hack Standard Library )] ( https://github.com/hhvm/hsl ) 3.30+
7+ - [ HSL Experimental] ( https://github.com/hhvm/hsl-experimental ) 3.30+
8+
9+ You can also test the command files by running from the command line :
10+
11+ ```
12+ $ hhvm count.hh
13+ 1
14+ 2
15+ 3
16+ 4
17+ 5
18+ 6
19+ 7
20+ 8
21+ 9
22+ 10
23+ ```
Original file line number Diff line number Diff line change 1+ #! / usr / bin / hhvm
2+ < ?hh // strict
3+
4+ use namespace HH\Lib\Str ;
5+ use function HH\Lib\Experimental\IO\request_output ;
6+ use function usleep ;
7+
8+ // Simple example script that counts to 10 at ~2Hz, then stops.
9+
10+ <<__EntryPoint >>
11+ async function count_to_ten (): Awaitable <noreturn > {
12+ $output = request_output ();
13+ for ($count = 1 ; $count <= 10 ; $count ++ ) {
14+ await $output -> writeAsync(
15+ Str \format (" %d\n " ,$count )
16+ );
17+
18+ // usleep is builtin, it is not an async builtin - so it also must block the main request thread
19+ usleep (500000 );
20+ }
21+
22+ // flush output
23+ await $output -> flushAsync();
24+
25+ exit (0 );
26+ }
Original file line number Diff line number Diff line change 1+ #! / usr / bin / hhvm
2+ < ?hh // strict
3+
4+ use namespace HH\Lib\Str ;
5+ use function HH\Lib\Experimental\IO\request_output ;
6+
7+ <<__EntryPoint >>
8+ async function dumpEnv (): Awaitable <noreturn > {
9+ // Standard CGI(ish) environment variables, as defined in
10+ // http://tools.ietf.org/html/rfc3875
11+ $names = keyset [
12+ ' AUTH_TYPE' ,
13+ ' CONTENT_LENGTH' ,
14+ ' CONTENT_TYPE' ,
15+ ' GATEWAY_INTERFACE' ,
16+ ' PATH_INFO' ,
17+ ' PATH_TRANSLATED' ,
18+ ' QUERY_STRING' ,
19+ ' REMOTE_ADDR' ,
20+ ' REMOTE_HOST' ,
21+ ' REMOTE_IDENT' ,
22+ ' REMOTE_PORT' ,
23+ ' REMOTE_USER' ,
24+ ' REQUEST_METHOD' ,
25+ ' REQUEST_URI' ,
26+ ' SCRIPT_NAME' ,
27+ ' SERVER_NAME' ,
28+ ' SERVER_PORT' ,
29+ ' SERVER_PROTOCOL' ,
30+ ' SERVER_SOFTWARE' ,
31+ ' UNIQUE_ID' ,
32+ ' HTTPS'
33+ ];
34+
35+ /* HH_IGNORE_ERROR[2050] using global variable */
36+ $server = dict ($_SERVER );
37+
38+ $ouput = request_output ();
39+
40+ foreach ($names as $name ) {
41+ await $output -> writeAsync(
42+ Str \format (" %s = %s\n " , $name , $server [$name ] ?? ' <unset>' )
43+ );
44+ }
45+
46+ // Additional HTTP headers
47+ foreach ($server as $k => $v ) {
48+ if ($k is string && Str \starts_with ($k , ' HTTP_' )) {
49+ await $output -> writeAsync(
50+ Str \format (" %s = %s\n " , $k , $v as string )
51+ );
52+ }
53+ }
54+
55+ // flush output
56+ await $output -> flushAsync();
57+
58+ exit (0 );
59+ }
Original file line number Diff line number Diff line change 1+ #! / usr / bin / hhvm
2+ < ?hh // strict
3+
4+ use namespace HH\Lib\Str ;
5+ use namespace HH\Lib\Experimental\IO ;
6+
7+ <<__EntryPoint >>
8+ async function greeter (): Awaitable <noreturn > {
9+ // For each line FOO received on STDIN, respond with "Hello FOO!".
10+ $input = IO \request_input ();
11+ $output = IO \request_output ();
12+ while (! $input -> isEndOfFile()) {
13+ await $ouput -> writeAsync(
14+ Str \format (" Hello %s!\n " , await $input -> readLineAsync())
15+ );
16+ }
17+
18+ // flush output
19+ await $output -> flushAsync();
20+
21+ exit (0 );
22+ }
You can’t perform that action at this time.
0 commit comments