Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84228 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 95436 invoked from network); 3 Mar 2015 11:55:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Mar 2015 11:55:31 -0000 Authentication-Results: pb1.pair.com header.from=me@kelunik.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=me@kelunik.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain kelunik.com from 81.169.146.219 cause and error) X-PHP-List-Original-Sender: me@kelunik.com X-Host-Fingerprint: 81.169.146.219 mo4-p00-ob.smtp.rzone.de Received: from [81.169.146.219] ([81.169.146.219:33406] helo=mo4-p00-ob.smtp.rzone.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AC/34-03783-131A5F45 for ; Tue, 03 Mar 2015 06:55:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1425383727; l=6092; s=domk; d=kelunik.com; h=Content-Type:Cc:To:From:Subject:Date:References:In-Reply-To: MIME-Version; bh=36auhakaRtUg0BA4m9GLL8MkpH245QxN6FEZ1E8J2Xs=; b=TTp5JIGHIbZQpzE3K7n4t74Pr1CDw0b0KYYtWeXuolA6GSLwksk5M0c68xegylKYCgT Ip693zDQnXLZpjuvK+Dd4z3ubs/EgXUUq7fmrTURpZesb3ZjQ1p+6FPKw2pt1Tut31gkV MlKX1eR0ovdMua1MU5s743jTmp5ME6tAm5I= X-RZG-AUTH: :IWkkfkWkbvHsXQGmRYmUo9mls2vWuiu+7SLGvomb4bl9EfHtPnRT9w== X-RZG-CLASS-ID: mo00 Received: from mail-we0-f174.google.com ([74.125.82.174]) by smtp.strato.de (RZmta 37.3 AUTH) with ESMTPSA id e00e32r23BtRGSb (using TLSv1.2 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) for ; Tue, 3 Mar 2015 12:55:27 +0100 (CET) Received: by wesp10 with SMTP id p10so37131962wes.12 for ; Tue, 03 Mar 2015 03:55:27 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.194.236.200 with SMTP id uw8mr66835219wjc.10.1425383727167; Tue, 03 Mar 2015 03:55:27 -0800 (PST) Received: by 10.27.77.131 with HTTP; Tue, 3 Mar 2015 03:55:27 -0800 (PST) In-Reply-To: <54F59C45.7080704@gmail.com> References: <54F59C45.7080704@gmail.com> Date: Tue, 3 Mar 2015 12:55:27 +0100 Message-ID: To: Rowan Collins Cc: Daniel Lowrey , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=089e01493f60ba06390510610289 Subject: Re: [PHP-DEV] [RFC Discuss] Generator Delegation From: me@kelunik.com (Niklas Keller) --089e01493f60ba06390510610289 Content-Type: text/plain; charset=UTF-8 2015-03-03 12:34 GMT+01:00 Rowan Collins : > > 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] $foo = getSession(42); > $json_data = $foo->current(); > $foo->send($json_data); > $decoded = $foo->getReturn(); Yes, it doesn't make sense if you call it directly, actually, this an example from my chat that uses the amp-framework ( https://github.com/amphp/amp), so this isn't called directly. To me, it isn't obvious that "yield final ..." makes the generator end, but anyone would know if there's a "return". Regards, Niklas --089e01493f60ba06390510610289--