Utilities for concurrent programming of PocketMine-MP plugins.

Overview


Utilities for concurrent programming of PocketMine-MP plugins

Overview

Plugin that implements the pthreads channels and in the future, promises (which are better than the defaults provided by PocketMine-MP) and even await.

How to work with threaded channels

Creating a channel can be done literally in one line, as shown below

$channel = new Channel();

Also, this implementation of threaded channels allows you to split one channel object into several other classes, such as: Reader, Writer and Closer. This allows you as a developer to give your plugin modules only what they need (For example, DiscordMessageSenderThread only needs to read from a channel). Here's how it's done

$reader = $channel->getReader();
$writer = $channel->getWriter();
$closer = $channel->getCloser();

(new DiscordMessageSenderThread($reader))->start();

You can just as easily write data to the channel (did you have any doubts?). But keep in mind that if you need to pass some object, then the first thing you need to do is serialize it. To do this, I advise you to use binary serialization - igbinary. Like this.

$obj = new stdClass();
$obj->message = "Hello, World!";

$writer->write(igbinary_serialize($obj));

To read the data, use the Reader::read() (or Channel::read()) method. Please note that the method signature contains the variable $wait, which is responsible for whether the thread will be blocked until there is data in the channel, or whether it will throw NoDataException exception.

try {
    $obj = igbinary_unserialize($reader->read(wait: true));
    // some code to send message to a Discord chat...
} catch (ClosedException) {
    break; // If the channel is closed, then stop the thread loop
}

And with non-blocking read...

try {
    $obj = igbinary_unserialize($reader->read(wait: false));
    // some code to send message to a Discord chat...
} catch (NoDataException) {
    continue;
} catch (ClosedException) {
    break; // If the channel is closed, then stop the thread loop
}

Upon completion of work, you can close the channel using the Closer::close() or Channel::close(). Then the next time your code try to write/read the ClosedException exception will be thrown. Look at example.

protected function onDisable(): void
{
    $this->closer->close();
}

And finally... CAT!

You might also like...
All about docker projects either from dockerfile or compose. Anyway, here the project is in the form of a service, for the programming language I will make it later
All about docker projects either from dockerfile or compose. Anyway, here the project is in the form of a service, for the programming language I will make it later

Docker Project by ItsArul Hey, yo guys okay, this time I made some projects from Docker. Anyway, this project is open source, for example, if you want

Small library providing some functional programming tools for PHP, based on Rambda

Functional library for PHP. Features: set of useful functions helpful in functional programming all functions are automatically curried every array ca

A Finite State Machine System based on Chapter 3.1 of Game Programming Gems 1 by Eric Dybsand

A Finite State Machine System based on Chapter 3.1 of Game Programming Gems 1 by Eric Dybsand,Written by Roberto Cezar Bianchini, July 2010 ported to php by MrFerrys.

A set of utilities for working with vk api!

vk-utils Документация на русском языке Installation composer require labile/vk-utils How to use it? Simple example use Astaroth\VkUtils\Client; $api

Open-source library used in Gigadrive projects with common PHP utilities

PHP Commons This library provides PHP utilities used in Gigadrive projects, provided for the open-source community. Functions are registered globally

This is php utilities

PHP-UTILITY This is php utilities. Requirements PHP = 7.4 Curl extension for PHP7 must be enabled. Download Using Composer From your project director

Magento-bulk - Bulk Import/Export helper scripts and CLI utilities for Magento Commerce

Magento Bulk Bulk operations for Magento. Configuration Copy config.php.sample to config.php and edit it. Product Attribute Management List All Attrib

This library provides a collection of native enum utilities (traits) which you almost always need in every PHP project.

This library provides a collection of native enum utilities (traits) which you almost always need in every PHP project.

Utilities to scan PHP code and generate class maps.

composer/class-map-generator Utilities to generate class maps and scan PHP code. Installation Install the latest version with: $ composer require comp

Owner
Dmitry Uzyanov
Dmitry Uzyanov
A PHP script that converts PMMP-3 Plugins into PMMP-4 plugins

This script tries to convert pm3 plugins to pm4 as good as possible, but sadly not perfect. Please open issues if you find any unexpected behaviour, to help improving this script.

null 43 Dec 3, 2022
This is a plugin written in PHP programming language and running on the PocketMine platform that works stably on the API 3.25.0 platform

This is a plugin written in PHP programming language and running on the PocketMine platform that works stably on the API 3.25.0 platform. It allows you to hear the sound

Thành Nhân 10 Sep 27, 2022
Plugins LevelSystem support Pocketmine-mp

Plugins LevelSystem support Pocketmine-mp

Ibenrm 8 Nov 24, 2022
UI virion (library) for PocketMine-MP plugins

Remark - Easy and Asynchronous Commands and Forms Quick Guide - Learn Remark by building a plugin. Install - Add Remark as a library to your plugin. E

DiamondStrider1 8 Jan 1, 2023
Simple game server with php without socket programming. Uses the Api request post(json).

QMA server Simple game server with php without socket programming. Uses the Api request post(json). What does this code do? Register the user as a gue

reza malekpour 3 Sep 4, 2021
Learning design patterns by implementing them in various programming languages.

design-patterns Learning design patterns by implementing them in various programming languages. Creational design patterns Creational design patterns

Paweł Tryfon 1 Dec 13, 2021
A repository for showcasing my knowledge of the PHP programming language, and continuing to learn the language.

Learning PHP (programming language) I know very little about PHP. This document will list all my knowledge of the PHP programming language. Basic synt

Sean P. Myrick V19.1.7.2 2 Oct 29, 2022
A simple functional programming library for PHP

bingo-functional A simple functional programming library for PHP. Requirement(s) PHP 7 or higher Rationale PHP, a language not commonly associated wit

Lochemem Bruno Michael 52 Sep 28, 2022
Bearer client for the PHP programming language

Bearer PHP Client This is the official PHP client for interacting with Bearer.sh. Installation Install the package by running: composer require bearer

Bearer 9 Oct 31, 2022
This example shows how to use Anychart library with the PHP programming language, Laravel framework and MySQL database.

PHP basic template This example shows how to use Anychart library with the PHP programming language, Laravel framework and MySQL database. Running To

AnyChart Integrations and Templates 23 Jul 17, 2022