Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples for hack lang #337

Merged
merged 15 commits into from
Jan 28, 2019
Prev Previous commit
Next Next commit
use noreturn type hint
  • Loading branch information
azjezz committed Jan 28, 2019
commit 69d4071fe57e6e1a02fdef5445e0a207382a8a9e
10 changes: 6 additions & 4 deletions examples/hack/dump-env.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use namespace HH\Lib\Str;
use function HH\Lib\Experimental\IO\request_output;

<<__EntryPoint>>
async function dumpEnv(): Awaitable<void> {
async function dumpEnv(): Awaitable<noreturn> {
// Standard CGI(ish) environment variables, as defined in
// http://tools.ietf.org/html/rfc3875
$names = keyset[
Expand Down Expand Up @@ -39,10 +39,10 @@ async function dumpEnv(): Awaitable<void> {

foreach($names as $name) {
await $output->writeAsync(
Str\format("%s = %s\n", $name, idx($server, $name, '<unset>'))
Str\format("%s = %s\n", $name, $server[$name] ?? '<unset>')
);
}

// Additional HTTP headers
foreach($server as $k => $v) {
if ($k is string && Str\starts_with($k, 'HTTP_')) {
Expand All @@ -51,7 +51,9 @@ async function dumpEnv(): Awaitable<void> {
);
}
}

// flush output
await $output->flushAsync();

exit(0);
}