Download the PHP package sue/coroutine without Composer

On this page you can find all versions of the php package sue/coroutine. 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 coroutine

sue/coroutine

提供基于sue/event-loop的协程组件

What is sue\coroutine

sue\coroutine是基于sue\event-loop事件循环生态的协程方案,底层是php的迭代器,但是针对php5版本做了兼容处理以及一些针对协程的控制逻辑。 sue\event-loop是基于流程的ReactPHP进行的开发

What is ReactPHP?

ReactPHP是一款基于PHP的事件驱动的组件。核心是提供EventLoop,然后提供基于EventLoop上的各种组件,比方说I/O处理等。sue/event-loop组件也是基于ReactPHP提供的EventLoop

环境需求

Table of Contents

install

$ composer require sue\coroutine 进行安装

requirements

php: >= 5.6.0

php5兼容方案

sue\coroutine是基于php generator实现。php7版本开始允许在迭代器中加入return用来控制返回,但是在php5的迭代器中使用return会报错。所以php5可以用Sue\Coroutine\SystemCall\returnValue来代替return

quickstart-example

functions

co

\Sue\Coroutine\co($callable) 可以将一段callable且是迭代器的代码以协程方式执行,如果callable非迭代器(generator)的话,那么会直接返回结果,使用方法如下:

coAs

\Sue\Coroutine\coAs($coroutine_class, $callable)方法同co, 区别是可以使用自定义的协程class(需要继承\Sue\Coroutine\Coroutine)。用此方法启动的协程中的子协程也会自动继承父级使用的自定义协程class

go

请不要使用, 计划未来移除 Sue\Coroutine\go($callable)方法和作用同co(),只是没有返回值

async

\Sue\Coroutine\async($callable, $timeout)方法可以临时启动一个eventloop来执行一段协程的代码, 当协程执行完毕或者超时后eventloop将被关闭. 该方法适用于传统的阻塞php模型(比如php-fpm)中使用异步的特性. 方法返回协程返回值或者抛出异常 该方法无法在一个已启动eventloop中使用

defer

Sue\Coroutine\defer($interval, $callable, ...$callable_params) 可以延迟一段时间再执行协程

pause

Sue\Coroutine\pause($seconds)可以生成一条系统指令,效果是让当前协程暂停执行并进行休眠,之后继续执行

sleep

建议用\Sue\Coroutine\SystemCall\pause方法代替,效果一致,此方法未来移除 Sue\Coroutine\SystemCall\sleep($seconds)效果同\Sue\Coroutine\SystemCall\pause($seconds)

timeout

\Sue\Coroutine\SystemCall\timeout($seconds)生成一个系统指令,可以为当前协程设置最大运行时间,如果超过运行时间,则会抛出异常

cancel

Sue\Coroutine\SystemCall\cancel($message, $code)生成一个系统指令,可以取消当前协程及其子协程,并抛出异常

returnValue

php7以上版本可以直接用return Sue\Coroutine\SystemCall\returnValue($value)生成一条系统指令,可以中止当前协程及子协程,并返回value值

tests

先安装dependencies

然后执行unit

License

The MIT License (MIT)

Copyright (c) 2023 Donghai Zhang

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


All versions of coroutine with dependencies

PHP Build Version
Package Version
Requires sue/event-loop Version ^1.2
react/promise Version ^2.9
react/promise-timer Version ^1.9
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 sue/coroutine contains the following files

Loading the files please wait ....