Skip to content

Commit 6e5bcbf

Browse files
committed
Using Amp\call
1 parent 0875b5a commit 6e5bcbf

File tree

2 files changed

+27
-31
lines changed

2 files changed

+27
-31
lines changed

src/macros.pre

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<?php
22

33
macro ·recursion {
4-
async function(···parameters) {···body}
4+
async function (···parameters) {···body}
55
} >> {
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());
6+
call_user_func(function ($outer) {
7+
return function (···parameters) use ($outer) {
8+
return Amp\call(
9+
call_user_func(function ($inner) use ($outer) {
10+
return function () use ($outer, $inner) {
11+
extract($outer);
12+
extract($inner);
13+
···body
14+
};
15+
}, get_defined_vars())
16+
);
1717
};
1818
}, get_defined_vars())
1919
}
@@ -22,14 +22,12 @@ macro ·recursion {
2222
async function ·ns()·function (···parameters) {···body}
2323
} >> {
2424
function ·function(···parameters) {
25-
return call_user_func(function($context) {
26-
$generator = function() use ($context) {
25+
return call_user_func(function ($context) {
26+
return Amp\call(function () use ($context) {
2727
extract($context);
2828

2929
···body
30-
};
31-
32-
return new \Amp\Coroutine($generator());
30+
});
3331
}, get_defined_vars());
3432
}
3533
}

tests/specs/async.spec

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,26 @@ $async = async function($path) {
1919
function read($path)
2020
{
2121
return call_user_func(function ($context·0) {
22-
$generator·0 = function () use ($context·0) {
22+
return Amp\call(function () use ($context·0) {
2323
extract($context·0);
2424

2525
$content = yield \Amp\File\get($path);
2626
return $content;
27-
};
28-
29-
return new \Amp\Coroutine($generator·0());
27+
});
3028
}, get_defined_vars());
3129
}
3230

3331
$async = call_user_func(function ($outer·1) {
3432
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());
43-
44-
return new \Amp\Coroutine($generator·1());
33+
return Amp\call(
34+
call_user_func(function ($inner·1) use ($outer·1) {
35+
return function () use ($outer·1, $inner·1) {
36+
extract($outer·1);
37+
extract($inner·1);
38+
$content = yield \Amp\File\get($path);
39+
return $content;
40+
};
41+
}, get_defined_vars())
42+
);
4543
};
4644
}, get_defined_vars());

0 commit comments

Comments
 (0)