Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103266 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 92608 invoked from network); 27 Sep 2018 06:04:16 -0000 Received: from unknown (HELO mail-oi1-f170.google.com) (209.85.167.170) by pb1.pair.com with SMTP; 27 Sep 2018 06:04:16 -0000 Received: by mail-oi1-f170.google.com with SMTP id k64-v6so813735oia.13 for ; Wed, 26 Sep 2018 19:12:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=SevmS1q31jEW8IGUxuZTYCuR7A1iBXqsg59OrJtUg6w=; b=suG9j9fI5rkK4aYdnoQTX9FcdsnV/34ZU8dXjYa7QJI9iFJYkgpCXoJ8Z4GOlws649 9qqsk7ZYFly7Bnrsc+/zgh40LgCbyweZJA+KU022tnRHZfe6Y9ija2LzWvdgCcSgt7/W fwYAT2m4dmUGN8VpLCUR0byPy5qLLXLixncROQWGk6WZb7DWEzIsatHp+Ka2OVjahc7z vraEi7abTByYzex7mqStLB1y0U8frbkN7VwYOTU+7ZF9K1B2NLG3pErMy1V+D2mHM0p7 KZEL/8nw4yX9a9OgNGXxs+Wir8TSrJ0S0X6SblSA1k/c8oiEBRV3/jsYuc844EEoDVkf dlrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=SevmS1q31jEW8IGUxuZTYCuR7A1iBXqsg59OrJtUg6w=; b=GR9stV76BCgl5NmykiKKdwj/pr7MsYXVUHuPaNmFEt7Zn8cM600KAd7crJkTfx3m00 Ov1/rqxqrcn4uJocFPCsNNieI7m0KpkOp4+glSRP489hZDqsnXXfMz8fuGTUOUpbhUEh zq4x/Pb3tZ1EvZuAzxbyUyVPIN9f4RPMpfhrLG4UkZU2mwpoNiBAYkt/Pgh5foydEScM c5xKxJquJ9gzk5td4t6oPePXnMidwzkf/JXz+kcsRpTGdSQeXFf5XyUTT5GYJLPjz9IZ EkJzCEmA9IUgBQ+5V1K/9Tw217u8FDnFD9B+AWT7yW3aLlhj8/uGcv34a5mOkUzC+qsf 8mKg== X-Gm-Message-State: ABuFfoi+ff2xhSnYvXfdjdbSGC7+vDVdXQlP1s3cj3A/nSyZA77P3YRD Jr/QPupM7zjo9UijeUPufifq4jAO2ebaoGnHiKE= X-Google-Smtp-Source: ACcGV60JdZgHuJd6xVU1cftlTH+XYbNv90C4O9mv/iP7e5lDLeNfHMENNDH7TD5tak0rUZtnYc1zCt5h+4IMtHRMZZA= X-Received: by 2002:aca:53c4:: with SMTP id h187-v6mr2189104oib.48.1538014351411; Wed, 26 Sep 2018 19:12:31 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 26 Sep 2018 23:12:20 -0300 Message-ID: To: David Rodrigues Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000134cf50576d0dfb5" Subject: Re: [PHP-DEV] Interruptions From: marcospassos.com@gmail.com (Marcos Passos) --000000000000134cf50576d0dfb5 Content-Type: text/plain; charset="UTF-8" Have you tried generators? It looks like you are trying to implement coroutines. You can learn more about cooperative multitasking in PHP on this awesome post written by Nikic: https://nikic.github.io/2012/12/22/Cooperative-multitasking-using-coroutines-in-PHP.html - Marcos On Wed, Sep 26, 2018 at 16:47 David Rodrigues wrote: > I do not know if I can get the same result with the current PHP features > without taking many turns. So I thought of a feature that I'm initially > calling "interruptions" (similar to those that occur on a CPU). > > Nowadays we have the Exceptions, which stop the execution of a function and > initiate a process of "catch" and treatment of the same. So I thought of > something similar, but did not break the execution flow, allowing reactions > to depend on what was happening inside a function. > > It would basically work according to the following flow (the square > brackets number is the execution order): > > function sum(int $a, int $b): int { > [2] interrupts with new SumInterruption($a, $b); > [5] return $a + $b; > } > > interruptable { > [6] $sum = [1] sum(1, 2); > [7] printf($sum); > } > [3] catch (SumInterruption $interruption) { > [4] printf('Calculating: %d + %d = ', $interruption->a, > $interruption->b); > } > > Using current PHP features I can do like that: > https://pastebin.com/Bci6BBfi > > Note that all code will be executed, and the interpection will only > redirect temporarily the execution flow to the "catch" block, then will > back to "sum()" block to return the sum. Like Exceptions, an Interruption > will traverse the code execution tree until find a interruption catch > block, but if it doesn't exists, just not will happen (or maybe throw > InterruptionNotHandledException or something like it). > > In one of my real example cases, I have a code that could be manipulated by > another method. Currently I need argument the self instance to this method, > so it could run another method from the caller method to make some > adjustments, which is a bit confuses. > > I hope you understand my point, and I am open to discuss that. > > Thanks! > > -- > David Rodrigues > --000000000000134cf50576d0dfb5--