Skip to content

Update documentation and examples to match version in early access #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/composer.lock
/vendor/
63 changes: 54 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,26 @@ built on top of [ReactPHP](https://reactphp.org/).

**Table of contents**

* [Support us](#support-us)
* [Quickstart example](#quickstart-example)
* [Install](#install)
* [License](#license)

## Support us

[![A clue·access project](https://raw.githubusercontent.com/clue-access/clue-access/main/clue-access.png)](https://github.com/clue-access/clue-access)

*This project is currently under active development,
you're looking at a temporary placeholder repository.*

The code is available in early access to my sponsors here: https://github.com/clue-access/reactphp-memoize

Do you sponsor me on GitHub? Thank you for supporting sustainable open-source, you're awesome! ❤️ Have fun with the code! 🎉

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.

This way, more people get a chance to take a look at the code before the public release.

## Quickstart example

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

## Install

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

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

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

Do you sponsor me on GitHub? Thank you for supporting sustainable open-source, you're awesome! ❤️ Have fun with the code! 🎉
```json
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/clue-access/reactphp-memoize"
}
]
}
```

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.
Then install this package as usual:

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

Rock on 🤘
This project aims to run on any platform and thus does not require any PHP
extensions and supports running on PHP 7.3 through current PHP 8+.

## Tests

To run the test suite, you first need to clone this repo and then install all
dependencies [through Composer](https://getcomposer.org/):

```bash
$ composer install
```

To run the test suite, go to the project root and run:

```bash
$ vendor/bin/phpunit
```

## License

This project will be released under the permissive [MIT license](LICENSE).
This project is released under the permissive [MIT license](LICENSE).

> Did you know that I offer custom development services and issuing invoices for
sponsorships of releases and for contributions? Contact me (@clue) for details.
38 changes: 38 additions & 0 deletions examples/database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

// $ php examples/database.php

use function Clue\React\Memoize\memoize;

require __DIR__ . '/../vendor/autoload.php';

/**
* @return React\Promise\PromiseInterface<int,Exception>
*/
function foo(int $id): React\Promise\PromiseInterface
{
$browser = new React\Http\Browser();
return $browser->get('http://httpbingo.org/status/' . $id)->then(function (Psr\Http\Message\ResponseInterface $response) {
return $response->getStatusCode();
});
}

//foo(200)->then('var_dump', 'printf');

$memoized = memoize('foo');

$memoized(200)->then('var_dump', 'printf');
$memoized(200)->then('var_dump', 'printf');
$memoized(200)->then('var_dump', 'printf');
$memoized(200)->then('var_dump', 'printf');
$memoized(200)->then('var_dump', 'printf');
$memoized(200)->then('var_dump', 'printf');

React\EventLoop\Loop::addTimer(0.01, function () use ($memoized) {
$memoized(200)->then('var_dump', 'printf');
});

$memoized(201)->then('var_dump', 'printf');
$memoized(201)->then('var_dump', 'printf');
$memoized(201)->then('var_dump', 'printf');
$memoized(201)->then('var_dump', 'printf');