-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 35be803
Showing
7 changed files
with
2,162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/vendor/ | ||
composer.phar |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/" | ||
} | ||
} | ||
} |
Oops, something went wrong.