Skip to content

Commit 5166348

Browse files
committed
Initial commit
0 parents  commit 5166348

11 files changed

+197
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor
2+
composer.lock

code-of-conduct.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Our Pledge
2+
3+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
4+
5+
# Our Standards
6+
7+
Examples of behavior that contributes to creating a positive environment include:
8+
9+
* Using welcoming and inclusive language
10+
* Being respectful of differing viewpoints and experiences
11+
* Gracefully accepting constructive criticism
12+
* Focusing on what is best for the community
13+
* Showing empathy towards other community members
14+
15+
Examples of unacceptable behavior by participants include:
16+
17+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
18+
* Trolling, insulting/derogatory comments, and personal or political attacks
19+
* Public or private harassment
20+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
21+
* Other conduct which could reasonably be considered inappropriate in a professional setting
22+
23+
# Our Responsibilities
24+
25+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
26+
27+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
28+
29+
# Scope
30+
31+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
32+
33+
# Enforcement
34+
35+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
36+
37+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
38+
39+
# Attribution
40+
41+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
42+
43+
[homepage]: http://contributor-covenant.org
44+
[version]: http://contributor-covenant.org/version/1/4

composer.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "pre/async",
3+
"license": "MIT",
4+
"require": {
5+
"php": "^7.0",
6+
"pre/plugin": "^0.5"
7+
},
8+
"autoload": {
9+
"files": [
10+
"src/bootstrap.php"
11+
]
12+
},
13+
"require-dev": {
14+
"phpunit/phpunit": "^5.0"
15+
},
16+
"autoload-dev": {
17+
"psr-4": {
18+
"Pre\\Async\\": "tests"
19+
}
20+
},
21+
"minimum-stability": "dev",
22+
"prefer-stable": true
23+
}

license.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright Christopher Pitt
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

phpunit.xml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<phpunit
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
bootstrap="tests/bootstrap.php"
6+
colors="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="false"
10+
processIsolation="false"
11+
stopOnFailure="false"
12+
syntaxCheck="false">
13+
<testsuites>
14+
<testsuite>
15+
<directory suffix="Test.php">tests</directory>
16+
</testsuite>
17+
</testsuites>
18+
</phpunit>

readme.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Pre Async
2+
3+
Documentation can be found at [preprocess.io](https://preprocess.io/docs#async).
4+
5+
## Versioning
6+
7+
This library follows [Semver](http://semver.org). According to Semver, you will be able to upgrade to any minor or patch version of this library without any breaking changes to the public API. Semver also requires that we clearly define the public API for this library.
8+
9+
All methods, with `public` visibility, are part of the public API. All other methods are not part of the public API. Where possible, we'll try to keep `protected` methods backwards-compatible in minor/patch versions, but if you're overriding methods then please test your work before upgrading.

src/bootstrap.php

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
Pre\addMacroPath(__DIR__ . "/macros.pre");

src/macros.pre

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
macro ·recursion {
4+
async
5+
function
6+
·optional(·ns())·function
7+
(···parameters)
8+
{···body}
9+
} >> {
10+
function ·function(···parameters) {
11+
return call_user_func(function($context) {
12+
$generator = function() use ($context) {
13+
extract($context);
14+
15+
···body
16+
};
17+
18+
return new \Amp\Coroutine($generator());
19+
}, get_defined_vars());
20+
}
21+
}

tests/SpecTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Pre\Async;
4+
5+
use Pre\Testing\Runner;
6+
7+
class SpecTest extends Runner
8+
{
9+
protected function path(): string
10+
{
11+
return __DIR__ . "/specs";
12+
}
13+
}

tests/bootstrap.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Yay;
4+
5+
// let's use a namespace trick, to make non-colliding variables predictable.
6+
7+
function md5($value) {
8+
return $value;
9+
}
10+
11+
putenv("PRE_BASE_DIR=" . __DIR__ . "/..");
12+
13+
require __DIR__ . "/../vendor/autoload.php";

tests/specs/async.spec

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--DESCRIPTION--
2+
3+
Test async macro
4+
5+
--GIVEN--
6+
7+
async function read($path) {
8+
$content = yield \Amp\File\get($path);
9+
return $content;
10+
}
11+
12+
$async = async function($path) {
13+
$content = yield \Amp\File\get($path);
14+
return $content;
15+
};
16+
17+
--EXPECT--
18+
19+
function read($path)
20+
{
21+
return call_user_func(function ($context·0) {
22+
$generator·0 = function () use ($context·0) {
23+
extract($context·0);
24+
25+
$content = yield \Amp\File\get($path);
26+
return $content;
27+
};
28+
29+
return new \Amp\Coroutine($generator·0());
30+
}, get_defined_vars());
31+
}
32+
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+
};
41+
42+
return new \Amp\Coroutine($generator·1());
43+
}, get_defined_vars());
44+
};

0 commit comments

Comments
 (0)