Skip to content

Commit 6b2f3b2

Browse files
authored
Merge pull request #3 from ace411/v0.x
v0.2.1 fixes
2 parents d0efa87 + dc21722 commit 6b2f3b2

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

src/internal/asyncify.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,13 @@ function asyncify(
6262
)
6363
->then(
6464
function (?string $result) {
65-
if (\preg_match('/(Error:)/', $result)) {
66-
return reject(new \Exception(head(\explode(PHP_EOL, $result))));
67-
}
65+
$data = \unserialize(\base64_decode($result));
6866

69-
if (\preg_match('/(Exception:)/', $result)) {
70-
return reject(new \Exception($result));
67+
if ($data instanceof \Throwable) {
68+
return reject(new \Exception($data->getMessage()));
7169
}
7270

73-
return resolve(\unserialize(\base64_decode($result)));
71+
return resolve($data);
7472
}
7573
);
7674
}

src/internal/constants.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function handleException(Throwable $exception): void
2222
}
2323
function handleError(...$args)
2424
{
25-
echo "Error: " . $args[1] . PHP_EOL;
25+
throw new \Exception($args[1]);
2626
}
2727
\set_error_handler("handleError", E_ALL);
2828
\set_exception_handler("handleException");
@@ -34,7 +34,7 @@ function (...$args) {
3434
return %s(...$args);
3535
},
3636
function ($err) {
37-
return "Exception: " . $err->getMessage();
37+
return new \Exception("Exception: " . $err->getMessage());
3838
}
3939
)(...\unserialize(\base64_decode("%s")))
4040
)

tests/AsyncTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function asyncifyProvider(): array
3131
['file_get_contents', ['foo.txt']],
3232
concat(
3333
' ',
34-
'Error: file_get_contents(foo.txt):',
34+
'Exception: file_get_contents(foo.txt):',
3535
PHP_VERSION_ID >= 80000 ? 'Failed' : 'failed',
3636
'to open stream: No such file or directory'
3737
),
@@ -41,8 +41,7 @@ public function asyncifyProvider(): array
4141
['file_get_contents', []],
4242
concat(
4343
' ',
44-
PHP_VERSION_ID >= 80000 ? 'Exception:' : 'Error:',
45-
'file_get_contents() expects at least 1',
44+
'Exception: file_get_contents() expects at least 1',
4645
PHP_VERSION_ID >= 80000 ? 'argument,' : 'parameter,',
4746
'0 given'
4847
),
@@ -53,7 +52,7 @@ public function asyncifyProvider(): array
5352
'(function ($file) { if (!\is_file($file)) { trigger_error("Could not find file " . $file); } return \file_get_contents($file); })',
5453
['foo.txt'],
5554
],
56-
'Error: Could not find file foo.txt',
55+
'Exception: Could not find file foo.txt',
5756
],
5857
// check if objects can be passed
5958
[

0 commit comments

Comments
 (0)