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

Internal Non-Blocking APIs #12

Open
tpunt opened this issue Apr 15, 2018 · 0 comments
Open

Internal Non-Blocking APIs #12

tpunt opened this issue Apr 15, 2018 · 0 comments

Comments

@tpunt
Copy link
Owner

tpunt commented Apr 15, 2018

Work has begun on the internal non-blocking APIs (see the non-blocking-io branch).

These APIs will allow for the automatic interruption of an actor when an IO operation is performed, where the actor will be placed into a blocked state. Once the IO operation has been performed, the actor will be rescheduled to continue its execution. This control flow should be seamless to the developer, and will enable for CPU usage to be maximised by allowing for other actors to continue executing (when previously the thread would be blocked by IO-blocking operations).

libuv is being utilised for these APIs. I have not yet decided whether to bundle it in with this extension's source code, or make it as another external dependency (like pthreads).

The currently planned APIs include:

<?php

namespace phactor;

class FileHandle
{
    function read(int $length) : string;
    function write(string $data) : bool;
}

Example:

<?php

use phactor\{ActorSystem, Actor, ActorRef, FileHandle};

class Test extends Actor
{
    public function receive()
    {
        try {
            $fh = new FileHandle(__FILE__); // causes a context switch to open the file
        } catch (Throwable $t) {
            var_dump($t->getMessage());
        }
        ActorSystem::shutdown();
    }
}

$actorSystem = new ActorSystem();

new ActorRef(Test::class);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant