Skip to content

async example do not work with hhvm v4 #710

Open
@AlphaWong

Description

@AlphaWong

Hi Community,

As I currently learn hacklang, It seems the sample code in this page https://docs.hhvm.com/hack/asynchronous-operations/some-basics is not runnable.

spec

hhvm --version
HipHop VM 4.18.0 (rel)
Compiler: 1565634828_N
Repo schema: 87cc9f3f8ece4c477c3bcf388b96a2a3031e653

issue

I find that if the run the sample code of

<?hh // strict

namespace Hack\UserDocumentation\AsyncOps\Basics\Examples\AsyncCurl;
use namespace HH\Lib\Vec;

async function curl_A(): Awaitable<string> {
  $x = await \HH\Asio\curl_exec("http://example.com/");
  return $x;
}

async function curl_B(): Awaitable<string> {
  $y = await \HH\Asio\curl_exec("http://example.net/");
  return $y;
}

async function async_curl(): Awaitable<void> {
  $start = \microtime(true);
  list($a, $b) = await Vec\from_async(vec[curl_A(), curl_B()]);
  $end = \microtime(true);
  echo "Total time taken: " . \strval($end - $start) . " seconds\n";
}

<<__EntryPoint>>
function main():void {
  \HH\Asio\join(async_curl());
}

It will always throw following error

Fatal error: Uncaught Error: Call to undefined function HH\Lib\Vec\from_async() in /Users/alphawong/works/src/github.com/alphawong/hello-hhvm/bin/async_func.hack:20
Stack trace:
#0 /Users/alphawong/works/src/github.com/alphawong/hello-hhvm/bin/async_func.hack(27): Hack\UserDocumentation\AsyncOps\Basics\Examples\AsyncCurl\async_curl()
#1 (): Hack\UserDocumentation\AsyncOps\Basics\Examples\AsyncCurl\main()
#2 {main}

When I Google it I find that I need to change require_once(__DIR__.'/../vendor/autoload.hack'); to require_once(__DIR__.'/../vendor/hh_autoload.hh); to make it runnable.

So I modify the currently sample code by split it to two file based on the hhvm version 4 like following added commit in order to let the tutorial working.

Please review my change.
#709

Best,
Alpha

Activity

AlphaWong

AlphaWong commented on Aug 14, 2019

@AlphaWong
ContributorAuthor

Also I have problem of the CI

Fatal error: Uncaught exception 'HH\InvariantException' with message 'none of /var/www/guides/hack/15-asynchronous-operations/04-some-basics-examples/async-curl.hack.example.hhvm.out, /var/www/guides/hack/15-asynchronous-operations/04-some-basics-examples/async-curl.hack.hhvm.expect, or /var/www/guides/hack/15-asynchronous-operations/04-some-basics-examples/async-curl.hack.no.auto.output exist.' in /var/www/src/markdown-extensions/ExampleIncludeBlock.php:101
Stack trace:
#0 /var/www/src/markdown-extensions/ExampleIncludeBlock.php(101): HH\invariant_violation()
#1 /var/www/src/markdown-extensions/ExampleIncludeBlock.php(68): HHVM\UserDocumentation\MarkdownExt\ExamplesIncludeBlock::getOutputBlock()
#2 /var/www/vendor/facebook/fbmarkdown/src/unparsed-blocks/ContainerBlock.php(68): HHVM\UserDocumentation\MarkdownExt\ExamplesIncludeBlock::consume()
#3 /var/www/vendor/facebook/fbmarkdown/src/unparsed-blocks/ContainerBlock.php(56): Facebook\Markdown\UnparsedBlocks\ContainerBlock::consumeSingleImpl()
#4 /var/www/vendor/facebook/fbmarkdown/src/unparsed-blocks/ContainerBlock.php(34): Facebook\Markdown\UnparsedBlocks\ContainerBlock::consumeSingle()
#5 /var/www/vendor/facebook/fbmarkdown/src/unparsed-blocks/Document.php(23): Facebook\Markdown\UnparsedBlocks\ContainerBlock::consumeChildren()
#6 /var/www/vendor/facebook/fbmarkdown/src/unparsed-blocks/parse.php(27): Facebook\Markdown\UnparsedBlocks\Document::consume()
#7 /var/www/vendor/facebook/fbmarkdown/src/parse.php(19): Facebook\Markdown\UnparsedBlocks\parse()
#8 /var/www/src/build/MarkdownRenderer.php(57): Facebook\Markdown\parse()
#9 /var/www/src/build/AbstractMarkdownRenderBuildStep.php(42): HHVM\UserDocumentation\MarkdownRenderer->renderMarkdownToHTML()
#10 /var/www/src/build/AbstractMarkdownRenderBuildStep.php(31): HHVM\UserDocumentation\AbstractMarkdownRenderBuildStep->renderFilesWithFBMarkdown()
#11 /var/www/src/build/GuidesHTMLBuildStep.php(30): HHVM\UserDocumentation\AbstractMarkdownRenderBuildStep->renderFiles()
#12 /var/www/bin/build.php(81): HHVM\UserDocumentation\GuidesHTMLBuildStep->buildAll()
#13 /var/www/bin/build.php(88): HHVM\UserDocumentation\build_site()
#14 {main}
The command '/bin/sh -c touch /docker_build && cd /var/www && .deploy/init.sh' returned a non-zero code: 255

How can I add the rename and add new file in the CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @AndrewDiMola@AlphaWong

        Issue actions

          async example do not work with hhvm v4 · Issue #710 · hhvm/user-documentation