Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Async Bundle Laravel Package

danilovl/async-bundle

View on GitHub
Deep Wiki
Context7

phpunit downloads latest Stable Version license

AsyncBundle

About

Symfony bundle provides simple delayed function call in AsyncListener after symfony send response.

The user gets a response faster because all unnecessary logic is processed later. For example: logging, creating rabbitmq queues or other unnecessary things.

Alt text

The user receives a response from the server much earlier and does not wait until unnecessary processes are finished.

Alt text

Requirements

  • PHP 8.5 or higher
  • Symfony 8.0 or higher

1. Installation

Install danilovl/async-bundle package by Composer:

composer require danilovl/async-bundle

Add the AsyncBundle to your application's bundles if does not add automatically:

<?php
// config/bundles.php

return [
    // ...
    Danilovl\AsyncBundle\AsyncBundle::class => ['all' => true]
];

2. Usage

AsyncService has simple three methods add, remove and reset.

<?php declare(strict_types=1);

namespace App\Controller;

use Danilovl\AsyncBundle\Attribute\PermissionMiddleware;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\{
    Request,
    Response
};

class HomeController extends AbstractController
{
    public function __construct(private AsyncService $asyncService)
    {
    }

    public function index(Request $request): Response
    {
        $this->asyncService->add(function () {
            // add callback with priority 0 and without name
        });

        $this->asyncService->add(function () {
            // add callback with priority 10
            // higher means sooner
        }, 10);    
        
        $this->asyncService->add(function () {
            // add callback with priority -10
            // less means later
        }, -10);    
        
        $this->asyncService->add(function () {
            // add callback with priority and name
        }, 90, 'sendEmail');     
        
        $this->asyncService->add(function () {
            // add second callback with priority and same name
        }, 100, 'sendEmail');
        
        // remove all callbacks with name 'sendEmail'
        $this->asyncService->remove(['sendEMail']);             
      
        // remove all callbacks with name 'sendEmail' and priority 
        $this->asyncService->remove(['sendEMail'], 100);        
        
        // remove all callbacks
        $this->asyncService->reset();

        return $this->render('home/index.html.twig');
    }
}

License

The AsyncBundle is open-sourced software licensed under the MIT license.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours