Skip to content

Commit 0875b5a

Browse files
committed
Changed how anonymous async functions work
1 parent 5166348 commit 0875b5a

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

src/macros.pre

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
<?php
22

33
macro ·recursion {
4-
async
5-
function
6-
·optional(·ns())·function
7-
(···parameters)
8-
{···body}
4+
async function(···parameters) {···body}
5+
} >> {
6+
call_user_func(function($outer) {
7+
return function(···parameters) use ($outer) {
8+
$generator = call_user_func(function($inner) use ($outer) {
9+
return function() use ($outer, $inner) {
10+
extract($outer);
11+
extract($inner);
12+
···body
13+
};
14+
}, get_defined_vars());
15+
16+
return new \Amp\Coroutine($generator());
17+
};
18+
}, get_defined_vars())
19+
}
20+
21+
macro ·recursion {
22+
async function ·ns()·function (···parameters) {···body}
923
} >> {
1024
function ·function(···parameters) {
1125
return call_user_func(function($context) {

tests/specs/async.spec

+12-10
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@ function read($path)
3030
}, get_defined_vars());
3131
}
3232

33-
$async = function ($path) {
34-
return call_user_func(function ($context·1) {
35-
$generator·1 = function () use ($context·1) {
36-
extract($context·1);
37-
38-
$content = yield \Amp\File\get($path);
39-
return $content;
40-
};
33+
$async = call_user_func(function ($outer·1) {
34+
return function ($path) use ($outer·1) {
35+
$generator·1 = call_user_func(function ($inner·1) use ($outer·1) {
36+
return function () use ($outer·1, $inner·1) {
37+
extract($outer·1);
38+
extract($inner·1);
39+
$content = yield \Amp\File\get($path);
40+
return $content;
41+
};
42+
}, get_defined_vars());
4143

4244
return new \Amp\Coroutine($generator·1());
43-
}, get_defined_vars());
44-
};
45+
};
46+
}, get_defined_vars());

0 commit comments

Comments
 (0)