Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112544 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 30156 invoked from network); 17 Dec 2020 22:40:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Dec 2020 22:40:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5D3841804C9 for ; Thu, 17 Dec 2020 14:11:52 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-40135.protonmail.ch (mail-40135.protonmail.ch [185.70.40.135]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 17 Dec 2020 14:11:50 -0800 (PST) Date: Thu, 17 Dec 2020 22:11:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1608243108; bh=wiKCbC0wiPHHsaNNvY4YmPTy4Si9tGQ6L2xPI2ja++I=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=m0X+335Ox2DwA7vjou3XL+PGJBTif5EcuXty1XhNfXEzvnc83e9T1hz169A1YFw/k xfh6a8uI4aJ2YAgbrUirfmawLXd0gywOVrek9tQExkMnGyIxEBckbL31gNfXtj5xbV +NpjNLtFUCugLuYLIRbmYFVR3w8SPyDBsrqHPHXQ= To: Aaron Piotrowski Cc: Peter Stalman , php internals Reply-To: Saif Eddin Gmati Message-ID: <36R8Ctg6RdOm8Ohh6Q_OZx0JNET8P_tTkbP03GbYuww57333-a1Zbn35nJmqIgwn3RLwRBwKESMdJX_bDsp9WEc2JEvyWS5hlwOb2qgkKt8=@protonmail.com> In-Reply-To: <461ED1D8-45CF-431C-91BA-959EF511CBBD@trowski.com> References: <461ED1D8-45CF-431C-91BA-959EF511CBBD@trowski.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Fibers From: azjezz@protonmail.com (Saif Eddin Gmati) Hello Aaron, First, I want to say that I love this proposal and would love to see it lan= d in the next PHP release, but I have one question regarding this: > Promises result in the =E2=80=9CWhat color is your function=E2=80=9D prob= lem as described in the introduction of the RFC. Returning promises from fu= nctions means that functions calling those functions must also return promi= ses, resulting in the entire call stack needing to return promises. Hack-Lang provides `HH\Asio\join` function which allows awaiting Awaitables= in sync code, so you are capable of running multiple async tasks concurren= tly without having to declare the entire call stack as "async" or with an "= Awaitable" return type, isn't this possible? ``` use namespace HH\Asio; async function async_task(): Awaitable { await Asio\usleep(1000000); } <<__EntryPoint>> function main(): void { $start =3D microtime(true); $async =3D async { concurrent { await async_task(); await async_task(); }; return 'hello'; }; $result =3D Asio\join($async); printf('Result: %s ( %f )', $result, microtime(true) - $start); // output= "Result: hello ( 1.010382 )" } ``` Regards, Saif. =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 Original Me= ssage =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 On Thursday, December 17, 2020 8:43 PM, Aaron Piotrowski wrote: > Hi Peter, > > > On Dec 17, 2020, at 1:23 PM, Peter Stalman sarkedev@gmail.com wrote: > > Hi Aaron, this is very interesting to me. Can I ask why this approach a= s > > opposed to other paradigms like promises, coroutines, etc? You mentione= d > > async/await in the future scope, and I assume most of these patterns ca= n be > > implemented once there is an underlying functionality. Basically, why > > fibers instead of x? > > Promises result in the =E2=80=9CWhat color is your function=E2=80=9D prob= lem as described in the introduction of the RFC. Returning promises from fu= nctions means that functions calling those functions must also return promi= ses, resulting in the entire call stack needing to return promises. > > Fibers are a method of implementing coroutines or interruptible functions= . Promises likely would still be used as placeholders in libraries using fi= bers, but coroutines written using fibers do not have to return another pla= ceholder. Fibers allow async code to be indistinguishable from sync code, a= s opposed to an approach where async functions must return a promise. > > > You also mentioned this isn't really intended to be used directly, but = with > > a library such as AMPHP. IS the expectation that non-blocking I/O > > functionality like database drivers and file operation be provided by > > libraries as well? > > Since most code written for PHP is blocking, yes, such libraries/framewor= ks would need to provide functionality such as database drivers. Both AMPHP= and ReactPHP already have existing async drivers available for several dif= ferent popular database systems. AMPHP=E2=80=99s postgres, mysql, and redis= drivers already have a version using fibers. > > > I hope I don't come off as critical, I am merely curious. Thank you for > > pushing this forward, as async is something PHP has been lacking and sh= ould > > have IMO to compare favourably to other alternatives that do. > > You didn=E2=80=99t com off as critical at all! These were good questions = to ask. I too think if PHP is to add support for async code it should compa= re favorably to other languages. I think fibers offer a distinct advantage = to using promise for async code. > > Cheers, > Aaron Piotrowski > > -------------------------------------------------------------------------= ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ----------------------------------------------------- > > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php