mcbeany / libasync
Stupid async implementation using await-generator
0.0.1
2022-06-25 14:02 UTC
Requires
- sof3/await-generator: ^3.4
Requires (Dev)
- pocketmine/pocketmine-mp: ^4.5
This package is auto-updated.
Last update: 2024-10-26 12:28:39 UTC
README
Stupid async implementation using await-generator
Usage
libAsync::doAsync(Closure $executor); // <-- Returns a promise
Example
- Fetch data from the internet
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
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