Skip to content
This repository was archived by the owner on Feb 21, 2025. It is now read-only.

Commit 74ff00b

Browse files
lexidorusox
authored andcommitted
Add ->moveToAsync()
Fixes #29 Will add to the interface in h-h-r-r-i shortly.
1 parent 3c65def commit 74ff00b

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

.hhconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ safe_vector_array = true
3737
typecheck_xhp_cvars = true
3838
unsafe_rx = false
3939
allowed_decl_fixme_codes=2053,4047
40-
allowed_fixme_codes_strict=2011,2049,2050,2053,4026,4027,4047,4053,4104,4107,4108,4110,4128,4135,4188,4200,4240,4248,4323
40+
allowed_fixme_codes_strict=2011,2049,2050,2053,4026,4027,4047,4053,4104,4107,4108,4110,4128,4135,4188,4200,4240,4248,4323,4390
4141
ignored_paths = [ "vendor/.+/tests/.+" ]

src/UploadedFile.hack

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Usox\HackTTP;
1111

1212
use namespace Facebook\Experimental\Http\Message;
13-
use namespace HH\Lib\{File, IO, Str};
13+
use namespace HH\Lib\{File, IO};
1414

1515
final class UploadedFile implements Message\UploadedFileInterface {
1616

@@ -38,14 +38,22 @@ final class UploadedFile implements Message\UploadedFileInterface {
3838
}
3939
}
4040

41+
/**
42+
* @deprecated HH\Asio\join() is bad for performance and could stall forever.
43+
*/
44+
<<__Deprecated('Use moveToAsync instead')>>
4145
public function moveTo(string $target_path): void {
46+
\HH\Asio\join($this->moveToAsync($target_path));
47+
}
48+
49+
public async function moveToAsync(string $target_path): Awaitable<void> {
4250
$this->validateActive();
43-
if (Str\length($target_path) === 0) {
51+
if ($target_path === '') {
4452
throw new \InvalidArgumentException(
4553
'Invalid path provided for move operation; must be a non-empty string',
4654
);
4755
}
48-
\HH\Asio\join($this->writeAsync($target_path));
56+
await $this->writeAsync($target_path);
4957

5058
$this->moved = true;
5159
}

tests/UploadedFileTest.hack

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class UploadedFileTest extends HackTest {
7878
Message\UploadedFileError::ERROR_CANCELED_BY_EXTENSION
7979
);
8080

81-
expect(() ==> $file->moveTo('/dev/null'))
81+
expect(async () ==> await $file->moveToAsync('/dev/null'))
8282
->toThrow(
8383
\RuntimeException::class,
8484
'Cannot retrieve stream due to upload error',
@@ -97,7 +97,7 @@ class UploadedFileTest extends HackTest {
9797
666
9898
);
9999

100-
$file->moveTo($filename);
100+
await $file->moveToAsync($filename);
101101
$ex = expect(() ==> $read_handle->close())->toThrow(
102102
OS\ErrnoException::class,
103103
);
@@ -110,7 +110,7 @@ class UploadedFileTest extends HackTest {
110110

111111
// after moving the file, the readhandle becomes invalid
112112

113-
expect(() ==> $file->moveTo('/dev/null'))
113+
expect(async () ==> await $file->moveToAsync('/dev/null'))
114114
->toThrow(
115115
\RuntimeException::class,
116116
'Cannot retrieve stream after it has already been moved',

0 commit comments

Comments
 (0)