Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"exception": "Non-static method VXM\\Async\\Async::run() should not be called statically", #10

Closed
valh1996 opened this issue Jun 17, 2020 · 3 comments

Comments

@valh1996
Copy link

Hello,

Whatever I do, your example gives me an error :

"exception": "Non-static method VXM\\Async\\Async::run() should not be called statically"

Here is my code based on your example :

public function index(Request $request)
{
    Async::run(function () {
        // Can I use a new instance of Laravel here?
        return 123;
    }, [
        'success' => function ($output) { 
            \Log::debug($output);
        },
        'timeout' => function () { 
            \Log::debug('timeout');
        },
        'error' => function (\Throwable $exception) {
            \Log::debug($exception->getMessage());
        },
    ]);
}

Do you have any idea please ?

Is it possible to use all the functions of Laravel in the child process please?

PS : Is it also possible to keep the child process open while the parent process has not been completed?

Thank you
Val'

@vuongxuongminh
Copy link
Owner

Hi, Make sure you are using Async facade not call direct to VXM\Async\Async. Yes, you can call all functions of Laravel in child process.

@valh1996
Copy link
Author

valh1996 commented Jun 18, 2020

Thanks!
So I can use all the functions of Laravel inside the child process, but we agree that it is not shared with the parent process? I have a singleton that I would like to "duplicate" (not the same user id) in the child process to make it communicate with the one in the parent process. I don't know if it's clear

Here is my complete new code :

<?php

namespace App\Console\Commands;

use Async;
use VXM\Async\Invocation;

class MyTask
{
    use Invocation;

    public function handle()
    {
        return 1;
    }
}


class test extends Command
{

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'test';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        Async::run(MyTask::class, [
            'success' => function ($output) {
                echo $output;
            },
            'error' => function (\Throwable $e) {
                var_dump($e->getMessage()); die;
            }
        ]);

        return true;
    }
}

I'm getting an empty error each time :

$: php artisan test
string(0) ""

Do you know why please? I can't get this piece of code to work :(

@vuongxuongminh
Copy link
Owner

Task should be PSR-4 named, can you rename and try again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants