Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84227 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 93183 invoked from network); 3 Mar 2015 11:35:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Mar 2015 11:35:25 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.173 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.173 mail-wi0-f173.google.com Received: from [209.85.212.173] ([209.85.212.173:45500] helo=mail-wi0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 94/D3-03783-C7C95F45 for ; Tue, 03 Mar 2015 06:35:25 -0500 Received: by wivz2 with SMTP id z2so2574102wiv.4 for ; Tue, 03 Mar 2015 03:35:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type; bh=eDl5WeWPN8lBjMXjO7Gq9dbpbNnLOWzFkhsZnXRu8Eo=; b=BS+3pR2qBaRZ7sfIazhgZ0DKUgMb/e5UYS7OHF4wUHeSO0YkiEcJcFusBrgEDhdkGM ttMN0ji4EKE3Bwu/wigFtZMGxNDou50U1GRUkzjK/qSKciQkrCQ1ZWHcQABS9Vug7QA5 RD9tNlDZaTElaGJ+gYdA4bAKBY49K09RTSyj/8XQ/zKNb95qKapdaZlC6hrkzydwP75S i2LoFpzlPlW7dxjzkM6oE+9f3rNflXOAUv3Xq/NWpGf/G0VSKKKjDvv2MDfhnMbLp7uk zwVsTILgL4puifY9eUh70e51Uev+WLPhermBEwEtfRKuzBsy7WFtObPsxijO/3MNLx7y KzRA== X-Received: by 10.194.60.173 with SMTP id i13mr67410667wjr.124.1425382521770; Tue, 03 Mar 2015 03:35:21 -0800 (PST) Received: from [192.168.0.159] ([62.189.198.114]) by mx.google.com with ESMTPSA id q10sm885654wjr.41.2015.03.03.03.35.19 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Mar 2015 03:35:21 -0800 (PST) Message-ID: <54F59C45.7080704@gmail.com> Date: Tue, 03 Mar 2015 11:34:29 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Niklas Keller CC: Daniel Lowrey , "internals@lists.php.net" References: In-Reply-To: Content-Type: multipart/alternative; boundary="------------050703090406000609070301" Subject: Re: [PHP-DEV] [RFC Discuss] Generator Delegation From: rowan.collins@gmail.com (Rowan Collins) --------------050703090406000609070301 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Niklas Keller wrote on 03/03/2015 10:55: > > Gr, top-posting... > > > Sorry, was on mobile. ;-) > > However, since the existence of the word "yield" is the only thing > that > marks a coroutine now, how about using a variant of that for the final > value, e.g. "yield final $foo"? > > > What's the final value? The last "yield"ed value or a return? "yield final" would mark the final result of the coroutine, as opposed to the intermediate values passed out with a normal "yield". > Just to give you some real world example: > If you're using "return", it would look like that: > > public function getSession ($sessionId) { > $result = yield $this->redis->get("session.{$sessionId}")); // > We're waiting here until redis responded. > return json_decode($result); > } My suggestion is simply to change the keyword: public function getSession ($sessionId) { $result = yield $this->redis->get("session.{$sessionId}")); // We're waiting here until redis responded. yield final json_decode($result); } The reasoning being that when you run getSession(42), it *doesn't* return the result of json_decode(), it returns a pointer to the coroutine's state, which you can resume later. Actually, I don't think that example makes sense, because JSON gets sent out at the first yield, and then sent back in, so the caller would look something like this: $foo = getSession(42); $json_data = $foo->current(); $foo->send($json_data); $decoded = $foo->getReturn(); But never mind, I think we both get the idea. I understand the desire for a "final result", but I don't like reusing the word "return", because it's never "returned" as the result of running the function, it's just made available through some specific method/syntax. Regards, -- Rowan Collins [IMSoP] --------------050703090406000609070301--