Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mcbeany committed Jun 24, 2022
0 parents commit 35be803
Show file tree
Hide file tree
Showing 7 changed files with 2,162 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor/
composer.phar
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# libAsync

Stupid async implementation using await-generator

## Usage
```php
libAsync::doAsync(Closure $executor); // <-- Returns a promise
```
## Example
- Fetch data from the internet
```php
use SOFe/AwaitGenerator/Await;
use Mcbeany/libAsync/libAsync;
use pocketmine/utils/Internet;

Await::f2c(function(){
$response = yield from libAsync::doAsync(fn() => Internet::getUrl("example.com"));
var_dump($response);
});
```
- Save file asynchronously
```php
Await::g2c(
libAsync::doAsync(fn() => file_put_contents('file.txt', 'Hello World!')),
fn() => $this->getLogger()->info("Saved file successfully!")
);
```
## Note
> Do not pass any variables that cannot be serialized to AsyncTask
17 changes: 17 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "mcbeany/libasync",
"description": "Stupid async implementation using await-generator",
"type": "library",
"license": "GPL-3.0-only",
"require": {
"sof3/await-generator": "^3.4"
},
"require-dev": {
"pocketmine/pocketmine-mp": "^4.5"
},
"autoload": {
"psr-0": {
"Mcbeany\\libAsync": "src/"
}
}
}
Loading

0 comments on commit 35be803

Please sign in to comment.