Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Expose an async variant of Codegen::forTree()
  • Loading branch information
lexidor committed May 29, 2023
commit 6dc6640e1a4695d077687e1233d0aef9855a0355
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use \Facebook\HackRouter\Codegen;

final class UpdateCodegen {
public function main(): void {
Codegen::forTree(
$codegen = await Codegen::forTree(
__DIR__.'/../src/',
shape(
'controllerBase' => WebController::class,
Expand All @@ -32,7 +32,8 @@ final class UpdateCodegen {
'class' => 'Router',
),
),
)->build;
);
$codegen->build();
}
}
```
Expand Down
12 changes: 9 additions & 3 deletions src/Codegen.hack
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,15 @@ final class Codegen {
self::TCodegenConfig $config,
): Codegen {
// leaving for now as it's a public API
/* HHAST_IGNORE_ERROR[DontUseAsioJoin] fix before final release */
return
new self(\HH\Asio\join(TreeParser::fromPathAsync($source_root)), $config);
/* HHAST_IGNORE_ERROR[DontUseAsioJoin] Kept for backward compatibility. */
return \HH\Asio\join(static::forTreeAsync($source_root, $config));
}

public static async function forTreeAsync(
string $source_root,
self::TCodegenConfig $config,
): Awaitable<Codegen> {
return new self(await TreeParser::fromPathAsync($source_root), $config);
}

<<__Memoize>>
Expand Down
4 changes: 2 additions & 2 deletions tests/CodegenTestCase.hack
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace Facebook\HackRouter;
use function Facebook\FBExpect\expect;

final class CodegenTestCase extends \Facebook\HackTest\HackTest {
public function testCanCreateForTree(): void {
public async function testCanCreateForTreeAsync(): Awaitable<void> {
// Just test it parses and we can create an instance
$codegen = Codegen::forTree(__DIR__.'/examples/', shape());
$codegen = await Codegen::forTreeAsync(__DIR__.'/examples/', shape());
expect($codegen)->toBeInstanceOf(Codegen::class);
}
}