<commit_before><?php

namespace Padawan\Framework\Application;

use Padawan\Framework\Application;
use Padawan\Framework\Application\Socket\SocketOutput;
use Symfony\Component\Console\Input\ArrayInput;
use Padawan\Command\CompleteCommand;
use Padawan\Command\KillCommand;
use Padawan\Command\ListCommand;
use Amp;

/**
 * Class Socket
 */
class Socket extends Application
{
    public function __construct()
    {
        parent::__construct("Padawan Server");
    }

    public function handle($request, SocketOutput $output)
    {
        if (!$request
            || !property_exists($request, "command")
            || !property_exists($request, "params")) {
            yield $output->write(json_encode([
                "error" => "Bad request"
            ]));
            return;
        }
        $arrayForInput = ['command' => $request->command];
        foreach($request->params as $key=>$value) {
            $arrayForInput[$key] =  $value;
        }
        $input = new ArrayInput($arrayForInput);
        $command = $this->find($request->command);
        try {
            yield Amp\resolve($command->run($input, $output));
        } catch (\Exception $e) {
            printf("Error: %s\n", $e->getMessage());
            yield $output->write(json_encode([
                "error" => $e->getMessage()
            ]));
        }
    }

    protected function loadCommands()
    {
        $this->add(new CompleteCommand);
        $this->add(new ListCommand);
        $this->add(new KillCommand);
    }
}
<commit_msg>added check for AsyncCommand to do resolve<commit_after><?php

namespace Padawan\Framework\Application;

use Amp;
use Padawan\Command\AsyncCommand;
use Padawan\Command\KillCommand;
use Padawan\Command\ListCommand;
use Padawan\Framework\Application;
use Padawan\Command\CompleteCommand;
use Symfony\Component\Console\Input\ArrayInput;
use Padawan\Framework\Application\Socket\SocketOutput;

/**
 * Class Socket
 */
class Socket extends Application
{
    public function __construct()
    {
        parent::__construct("Padawan Server");
    }

    public function handle($request, SocketOutput $output)
    {
        if (!$request
            || !property_exists($request, "command")
            || !property_exists($request, "params")) {
            yield $output->write(json_encode([
                "error" => "Bad request"
            ]));
            return;
        }
        $arrayForInput = ['command' => $request->command];
        foreach($request->params as $key=>$value) {
            $arrayForInput[$key] =  $value;
        }
        $input = new ArrayInput($arrayForInput);
        $command = $this->find($request->command);
        try {
            if ($command instanceof AsyncCommand) {
                yield Amp\resolve($command->run($input, $output));
            }
        } catch (\Exception $e) {
            printf("Error: %s\n", $e->getMessage());
            yield $output->write(json_encode([
                "error" => $e->getMessage()
            ]));
        }
    }

    protected function loadCommands()
    {
        $this->add(new CompleteCommand);
        $this->add(new ListCommand);
        $this->add(new KillCommand);
    }
}

{'fraction_non_alphanumeric': 0.14021909233176838, 'fraction_numerical': 0.0, 'mean_word_length': 2.353620146904512, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '7548494', 'n_tokens_mistral': 897, 'n_tokens_neox': 891, 'n_words': 174}