<commit_before><?php

namespace Amp\Loop;

use Amp\Coroutine;
use Amp\Promise;
use React\Promise\PromiseInterface as ReactPromise;
use function Amp\Promise\rethrow;

class UvDriver extends Driver {
    /** @var resource A uv_loop resource created with uv_loop_new() */
    private $handle;

    /** @var resource[] */
    private $events = [];

    /** @var \Amp\Loop\Watcher[]|\Amp\Loop\Watcher[][] */
    private $watchers = [];

    /** @var int[] */
    private $io = [];

    /** @var resource[] */
    private $streams = [];

    /** @var callable */
    private $ioCallback;

    /** @var callable */
    private $timerCallback;

    /** @var callable */
    private $signalCallback;

    public function __construct() {
        $this->handle = \uv_loop_new();

        $this->ioCallback = function ($event, $status, $events, $resource) {
            $watchers = $this->watchers[(int) $event];

            switch ($status) {
                case 0: // OK
                    break;

                // If $status is a severe error, disable all related watchers and notify the loop error handler.
                case \UV::EACCES:
                case \UV::EBADF:
                case \UV::EINVAL:
                case \UV::ENOTSOCK:
                    foreach ($watchers as $watcher) {
                        $this->disable($watcher);
                    }
                    $this->error(new \Error(
                        \sprintf("UV_%s: %s", \uv_err_name($status), \ucfirst(\uv_strerror($status)))
                    ));
                    return;

                default: // Ignore other (probably) trivial warnings and continuing polling.
                    return;
            }

            foreach ($watchers as $watcher) {
                if (!($watcher->enabled && $watcher->type & $events)) {
                    continue;
                }

                try {
                    $result = ($watcher->callback)($watcher->id, $resource, $watcher->data);

                    if ($result === null) {
                        continue;
                    }

                    if ($result instanceof \Generator) {<commit_msg>Only poll again on UV_EAGAIN<commit_after><?php

namespace Amp\Loop;

use Amp\Coroutine;
use Amp\Promise;
use React\Promise\PromiseInterface as ReactPromise;
use function Amp\Promise\rethrow;

class UvDriver extends Driver {
    /** @var resource A uv_loop resource created with uv_loop_new() */
    private $handle;

    /** @var resource[] */
    private $events = [];

    /** @var \Amp\Loop\Watcher[]|\Amp\Loop\Watcher[][] */
    private $watchers = [];

    /** @var int[] */
    private $io = [];

    /** @var resource[] */
    private $streams = [];

    /** @var callable */
    private $ioCallback;

    /** @var callable */
    private $timerCallback;

    /** @var callable */
    private $signalCallback;

    public function __construct() {
        $this->handle = \uv_loop_new();

        $this->ioCallback = function ($event, $status, $events, $resource) {
            $watchers = $this->watchers[(int) $event];

            switch ($status) {
                case 0: // OK
                    break;

                case \UV::EAGAIN: // Resource temporarily unavailable.
                    $flags = 0;
                    foreach ($this->watchers[(int) $event] as $watcher) {
                        $flags |= $watcher->enabled ? $watcher->type : 0;
                    }
                    \uv_poll_start($event, $flags, $this->ioCallback); // Poll must be reactivated.
                    return;

                default: // Disable all related watchers and notify the loop error handler.
                    foreach ($watchers as $watcher) {
                        $this->disable($watcher);
                    }
                    $this->error(new \Error(
                        \sprintf("UV_%s: %s", \uv_err_name($status), \ucfirst(\uv_strerror($status)))
                    ));
                    return;
            }

            foreach ($watchers as $watcher) {
                if (!($watcher->enabled && $watcher->type & $events)) {
                    continue;
                }

                try {
                    $result = ($watcher->callback)($watcher->id, $resource, $watcher->data);

                    if ($result === null) {
                        continue;
                    }

                    if ($result instanceof \Generator) {
{'fraction_non_alphanumeric': 0.1358219024061165, 'fraction_numerical': 0.0008994827973914999, 'mean_word_length': 1.4656319290465631, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6052797', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1145, 'n_words': 293}