Skip to content

Latest commit

 

History

History
70 lines (52 loc) · 1.7 KB

rpc.md

File metadata and controls

70 lines (52 loc) · 1.7 KB

RPC

Asynchronous blocking RPC calls

Asynchronous RPC can be obtained in addition to the results of the return. You can also concurrently execute multitasking, execute multiple tasks that are not dependent on each other, and reduce the response time of the application.

use \MQK\Queue\Invoke;
use MQK\Queue\Invokes;

$invoke = K::invokeAsync(
    new Invokes(
        new Invoke('a', 'Calculator::sum', 1, 1),
        new Invoke('b', 'Calculator::sum', 2, 2),
        new Invoke('c', 'Calculator::sum', 3, 3),
        new Invoke('d', 'Calculator::sum', 4, 4)
    )
);

new Invoke('a', 'Calculator::sum', 1, 1)

Invoke has three parameters, the first parameter sets the key name of the RPC, the second argument is the method name, and the remaining argument is the parameter of the method call.

  1. Query result
$invoke->wait();

extract($invoke->returns());

$invoke->wait(); Waiting for all RPC tasks to finish

extract($invoke->returns());returns() Will return multiple RPC results to hash table, extract the hash key as the current function of the variable.

assert($a == 2);
assert($b == 4);
assert($c == 6);
assert($d == 8);

Asynchronous does not block RPC calls

class Calculator
{    
    public function sum($a, $b)
    {
        return $a + $b;
    }
}

Asynchronously call RPC

\K::invoke('Calculator::sum', 1, 2);