Download the PHP package colinhdev/libasyncevent without Composer

On this page you can find all versions of the php package colinhdev/libasyncevent. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package libasyncevent

libAsyncEvent

libAsyncEvent provides you with multiple implementations for creating asynchronous event execution for PocketMine-MP plugins.

Why should I use this library?

I came to the idea for this library while implementing libasynql and await-generator to my plugin CPlot. I then realised how annoying it is, to deal with PocketMine-MP's events in this case, since it is not possible e.g. to check if a player is allowed to build in a certain area with an asynchronous-run query.

So when deciding to implement custom events into the plugin, I wanted to make it as developer-friendly as possible. So when someone decides to work with the events, they are not forced to directly decide, how to react (e.g. cancelling the event) and be allowed e.g. to run asynchronous queries to validate their decision.

How to use this library in my plugin?

How should my event class look like?

Normally your event class looks like this: It extends PocketMine-MP's Event class or one of its subclasses and maybe also implements an interface like the Cancellable one.

First, implement the AsyncEvent interface, which this library provides, to your event class. And second, use one of the EventHandlerExecutionTraits in your event class:

There are multiple EventHandlerExecutionTraits, which you can use and each of them has a different behaviour:

How can I call my event?

You can simply call your event by creating a new event instance and using its call() method.

But to get the result of the event, you need to provide a callback function which will be run when all listeners are finished.

How to improve my event class?

Unless both you and the person trying to register a listener for your async event use composer, they will not be able to correctly see libAsyncEvent's declared methods like block() or release() in their IDE.

Although ideally composer should be used to develop plugins and to declare their dependencies, we can not force anyone to do so. So to make it easier for them, you can add following PHPDoc comments to your event class:

This way, the IDE will know that these methods exist and will not show any errors.

How to handle an event made with this library?

To register an event listener for an async event, you can do it the same way, you would normally do it for every other event listener:

In this class, you as well create a method which accepts the event, you want to listen to, as a parameter:

So basically there is no difference between a normal event listener and our async event listener. But if you want to keep the event instance from continuing with its execution, you need to call the block() method. This way the event won't finish its execution until you call the release() method.

If you accidentally forget to call the release() method, an exception will be thrown once the event instance is destroyed by the garbage collector.


All versions of libasyncevent with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
pocketmine/pocketmine-mp Version ^5.5.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package colinhdev/libasyncevent contains the following files

Loading the files please wait ....