Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64325 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94543 invoked from network); 17 Dec 2012 21:29:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Dec 2012 21:29:59 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:37992] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 74/B2-65234-5DE8FC05 for ; Mon, 17 Dec 2012 16:29:58 -0500 Received: by mail-lb0-f170.google.com with SMTP id j14so37943lbo.29 for ; Mon, 17 Dec 2012 13:29:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=+QbZr67Hm6UTht2Uto+2Jh3mV6YufwS233QBt+KioK4=; b=G/iU719ZPpITreJAw3eupWHwdkwTmvsvo+693Eu8JjYLopIEZfaVNucYlxKGlR/VuR /PGvgHcEzApwHV/cD3rf0VPH0qUD2CgZTUh0KDkpXYZDMc01gtqHlu0DQG0V84ec8srU v6vnTDDbnTBSMDtVbNhRpr8gMVpPX223xApBWH+HTIhxL0TQsx/VOHFi4p47wexuN2yd koLOoyWI37FBkVTFKJYtNnSL8Y1I8200N9m3Gp6nzQb+zz0nlS+8TtokPN9ZVWah5Bku bfumkFmH+ur0KPEQ1fKqk3HnPDRRznnu+pnDeiqkVWkb7lpXIJkVlZ9olo8Vn8mosZ1q XG9Q== MIME-Version: 1.0 Received: by 10.152.148.40 with SMTP id tp8mr12350991lab.30.1355779794818; Mon, 17 Dec 2012 13:29:54 -0800 (PST) Received: by 10.112.39.130 with HTTP; Mon, 17 Dec 2012 13:29:54 -0800 (PST) Date: Mon, 17 Dec 2012 22:29:54 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary=e89a8f23466510570c04d1131576 Subject: Adding Generator::throw() From: nikita.ppv@gmail.com (Nikita Popov) --e89a8f23466510570c04d1131576 Content-Type: text/plain; charset=ISO-8859-1 Hey internals! I would like to add a ->throw() method to generator objects and as this wasn't part of the proposal that was voted on I'd like to ask back first. The Generator::throw(Exception $exception) method takes an exception and throws it at the current interruption point in the generator. It basically behaves as if you replaced the current yield statement with a throw statement and resumed the generator. This method is also part of Python's generator implementation (as well as ECMAScript's). I decided not to implement it at first, because I wasn't convinced of its usefulness. But after some further consideration adding it seems to make more sense. Basically the method allows you to do delegate error handling to the coroutine, rather than doing it yourself (as you are not always able to do it). It is particularly useful in more complicated settings, e.g. if you are doing task scheduling through coroutines. For a small sample of how this looks like see http://taskjs.org/. What the ->throw() method would do in these examples is that it allows to check for errors by try/catching the yield statement (rather than going for some odd solution with error callbacks). Here is a patch that would add this functionality: https://github.com/nikic/php-src/commit/b16e29fea6cba576d4176524bf43d6e7d00f45fa Anyone against adding this? Nikita --e89a8f23466510570c04d1131576--