承接 onion/promise 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

onion/promise

Composer 安装命令:

composer require onion/promise

包简介

README 文档

README

Build Status Mutation testing badge

This is an Promises/A+ implementation that should be fully compatible with any already existing implementations without any 3rd party dependencies.

This package defines 2 interfaces PromiseInterface & ThenableInterface as per the spec also there are some helper functions as well as some that provide a more sugary feel to the code.

is_thenable - Function that checks if an object is "thenable" coroutine - Push a task as a promise. This one changes it's implementation depending on whether or not the swoole extension is available on the server. If it is then the native coroutines available as go function are used, alternatively it falls back to an approach similar to an event loop.

A tick function is registered using register_tick_function that will invoke 1 task per so that not to bring your application to a complete halt when executing. As well as there is a function registered for shutdown that will run all remaining tasks in a blocking way until the queue is empty - albeit hanging the request.

For when the synchronous mode is used, you should do declare(ticks=1) see the PHP Docs

NOTE: Please, keep in mind that your code will block until the task is processed so this 'mode' is not recommended and users should look at alternative approaches for their heavy tasks or install swoole

async - alias for coroutine, intended to mimic the async keyword in JS/TS/C#

==============

Usage

use \Onion\Framework\Promise\async;

$promise = async(function () use ($orm, $id, $password) {
    $user = $orm->findById($id); // if it throws any exception the promise will immediately get rejected

    if (!$user->isActive()) {
        throw new \RuntimeException('User is not activated yet');
    }

    if (!password_verify($password, $user->getPassword())) {
        throw new \InvalidArgumentException('Invalid password provided');
    }

    return $user;
})->then(function (User $user) use ($paymentService) {
    $paymentService->processUserPayment($user->getId());
    echo "User {$user->getId()} processed successfully";
}, function (\Throwable $ex) {
    echo "Ops.. {$ex->getMessage()}";
})->otherwise(function (\Throwable $ex) {
    // Do something else with the exception maybe ?
})->finally(function () use ($orm) {
    // Regardless of the state change, but it is always called at the end of execution
    $orm->disconnect();
});

The function passed to async/coroutine will be executed immediately so do keep in mind that when using without swoole.

onion/promise 适用场景与选型建议

onion/promise 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 309 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 01 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 onion/promise 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 onion/promise 我们能提供哪些服务?
定制开发 / 二次开发

基于 onion/promise 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 309
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 4
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-01-21