Hprose\Service::multicast PHP Method

multicast() public method

public multicast ( $topic, $ids, $result, $callback = null )
    public function multicast($topic, $ids, $result, $callback = null)
    {
        $this->checkPushService();
        if (!is_callable($callback)) {
            foreach ($ids as $id) {
                $this->internalPush($topic, $id, $result);
            }
            return;
        }
        $sent = array();
        $unsent = array();
        $n = count($ids);
        $count = $n;
        $check = function ($id) use(&$sent, &$unsent, &$count, $callback) {
            return function ($success) use($id, &$sent, &$unsent, &$count, $callback) {
                if ($success) {
                    $sent[] = $id;
                } else {
                    $unsent[] = $id;
                }
                if (--$count === 0) {
                    call_user_func($callback, $sent, $unsent);
                }
            };
        };
        for ($i = 0; $i < $n; ++$i) {
            $id = $ids[$i];
            if ($id !== null) {
                $this->internalPush($topic, $id, $result)->then($check($id));
            } else {
                --$count;
            }
        }
    }