Skip to content

Commit d27fc85

Browse files
authored
Merge pull request #6 from SimonFrings/documentation
Update documentation and examples to match version in early access
2 parents 0f43ec5 + 5a30d4d commit d27fc85

File tree

3 files changed

+94
-9
lines changed

3 files changed

+94
-9
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/composer.lock
2+
/vendor/

README.md

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,26 @@ built on top of [ReactPHP](https://reactphp.org/).
55

66
**Table of contents**
77

8+
* [Support us](#support-us)
89
* [Quickstart example](#quickstart-example)
910
* [Install](#install)
1011
* [License](#license)
1112

13+
## Support us
14+
15+
[![A clue·access project](https://raw.githubusercontent.com/clue-access/clue-access/main/clue-access.png)](https://github.com/clue-access/clue-access)
16+
17+
*This project is currently under active development,
18+
you're looking at a temporary placeholder repository.*
19+
20+
The code is available in early access to my sponsors here: https://github.com/clue-access/reactphp-memoize
21+
22+
Do you sponsor me on GitHub? Thank you for supporting sustainable open-source, you're awesome! ❤️ Have fun with the code! 🎉
23+
24+
Seeing a 404 (Not Found)? Sounds like you're not in the early access group. Consider becoming a [sponsor on GitHub](https://github.com/sponsors/clue) for early access. Check out [clue·access](https://github.com/clue-access/clue-access) for more details.
25+
26+
This way, more people get a chance to take a look at the code before the public release.
27+
1228
## Quickstart example
1329

1430
Once [installed](#install), you can use the following code to decorate a demo
@@ -45,24 +61,53 @@ function multiple times.
4561

4662
## Install
4763

48-
[![A clue·access project](https://raw.githubusercontent.com/clue-access/clue-access/main/clue-access.png)](https://github.com/clue-access/clue-access)
64+
The recommended way to install this library is [through Composer](https://getcomposer.org/).
65+
[New to Composer?](https://getcomposer.org/doc/00-intro.md)
4966

50-
*This project is currently under active development,
51-
you're looking at a temporary placeholder repository.*
67+
This project does not yet follow [SemVer](https://semver.org/).
68+
This will install the latest supported version:
5269

53-
The code is available in early access to my sponsors here: https://github.com/clue-access/reactphp-memoize
70+
While in [early access](#support-us), you first have to manually change your
71+
`composer.json` to include these lines to access the supporters-only repository:
5472

55-
Do you sponsor me on GitHub? Thank you for supporting sustainable open-source, you're awesome! ❤️ Have fun with the code! 🎉
73+
```json
74+
{
75+
"repositories": [
76+
{
77+
"type": "vcs",
78+
"url": "https://github.com/clue-access/reactphp-memoize"
79+
}
80+
]
81+
}
82+
```
5683

57-
Seeing a 404 (Not Found)? Sounds like you're not in the early access group. Consider becoming a [sponsor on GitHub](https://github.com/sponsors/clue) for early access. Check out [clue·access](https://github.com/clue-access/clue-access) for more details.
84+
Then install this package as usual:
5885

59-
This way, more people get a chance to take a look at the code before the public release.
86+
```bash
87+
$ composer require clue/reactphp-memoize:dev-main
88+
```
6089

61-
Rock on 🤘
90+
This project aims to run on any platform and thus does not require any PHP
91+
extensions and supports running on PHP 7.3 through current PHP 8+.
92+
93+
## Tests
94+
95+
To run the test suite, you first need to clone this repo and then install all
96+
dependencies [through Composer](https://getcomposer.org/):
97+
98+
```bash
99+
$ composer install
100+
```
101+
102+
To run the test suite, go to the project root and run:
103+
104+
```bash
105+
$ vendor/bin/phpunit
106+
```
62107

63108
## License
64109

65-
This project will be released under the permissive [MIT license](LICENSE).
110+
This project is released under the permissive [MIT license](LICENSE).
66111

67112
> Did you know that I offer custom development services and issuing invoices for
68113
sponsorships of releases and for contributions? Contact me (@clue) for details.

examples/database.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
// $ php examples/database.php
4+
5+
use function Clue\React\Memoize\memoize;
6+
7+
require __DIR__ . '/../vendor/autoload.php';
8+
9+
/**
10+
* @return React\Promise\PromiseInterface<int,Exception>
11+
*/
12+
function foo(int $id): React\Promise\PromiseInterface
13+
{
14+
$browser = new React\Http\Browser();
15+
return $browser->get('http://httpbingo.org/status/' . $id)->then(function (Psr\Http\Message\ResponseInterface $response) {
16+
return $response->getStatusCode();
17+
});
18+
}
19+
20+
//foo(200)->then('var_dump', 'printf');
21+
22+
$memoized = memoize('foo');
23+
24+
$memoized(200)->then('var_dump', 'printf');
25+
$memoized(200)->then('var_dump', 'printf');
26+
$memoized(200)->then('var_dump', 'printf');
27+
$memoized(200)->then('var_dump', 'printf');
28+
$memoized(200)->then('var_dump', 'printf');
29+
$memoized(200)->then('var_dump', 'printf');
30+
31+
React\EventLoop\Loop::addTimer(0.01, function () use ($memoized) {
32+
$memoized(200)->then('var_dump', 'printf');
33+
});
34+
35+
$memoized(201)->then('var_dump', 'printf');
36+
$memoized(201)->then('var_dump', 'printf');
37+
$memoized(201)->then('var_dump', 'printf');
38+
$memoized(201)->then('var_dump', 'printf');

0 commit comments

Comments
 (0)