Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Question] What is the best way to submit tasks to the Worker Pool from Request Handler? #382

@barbosa89

Description

@barbosa89

I'm trying to send tasks to the Worker Pool from a Request Handler. The Worker Pool initializes correctly. I wonder if this is the correct way or if it has to be done inside an async function. I appreciate your valuable help.

// Initialization code

$server->start(new class implements RequestHandler {
    public function handleRequest(Request $request): Response
    {
        $execution = Worker\submit(new FetchTask('https://google.com'));
        $execution->await();

        return new Response(
            status: HttpStatus::OK,
            headers: ["content-type" => "text/plain; charset=utf-8"],
            body: "Hello, World!",
        );
    }
}, new DefaultErrorHandler());

// Rest of code

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions