Error while using Amphp parallel with user defined function

Viewed 787

I am trying to call a user-defined function using Worker\enqueueCallable.
I have put the function in a separate file and used composer to autoload it.

And I am getting the error :

Fatal error: Uncaught TypeError: Argument 1 passed to Amp\Parallel\Worker\enqueueCallable() must be callable, string given"

My folder structure

Project Folder/
    app/
       funcs.php
       caller.php
    main.php
    composer.json

Used namespace app on top in both caller.php and funcs.php

And then in composer.json used the following snippet and used composer dumpautoload -o

{
    "autoload": {
        "psr-4": {
            "app\\": "app/"
        },
        "files": [ "app/funcs.php" ]
    },
    "require": {
        "amphp/parallel": "^1.3",
        "amphp/parallel-functions": "^0.1.3"
    }

} 

From main.php I am calling caller.php which calls a function defined in funcs.php

funcs.php

namespace app;
function f1($param1){
  #Do some stuff 
}

caller.php

namespace app;

use Amp\Parallel\Worker;
use Amp\Promise;

class cls
{
    function __construct()
    {

    }

    function Invoker()
    {
        // If I call the function, its working.
        f1($param1);
        // When I am using its not working.
        $promises[] = Worker\enqueueCallable('f1', $param1);  
    }

}

main.php

require __DIR__ . '\vendor\autoload.php';
use app\cls;

$obj = new cls();
$obj->Invoker();

I am using windows-10, WAMP server, with PHP version 7.3.5.

0 Answers
Related