Giter Club home page Giter Club logo

Comments (7)

clue avatar clue commented on May 21, 2024

I'm not sure I follow what you're doing, can you provide a gist to reproduce this?

In case you're calling tick() will the loop is running, this is probably where the problem comes from. This should not be done, ever.

from event-loop.

nick4fake avatar nick4fake commented on May 21, 2024

@clue Please check this library:
https://github.com/WyriHaximus/reactphp-psr7-stream-converter/blob/master/src/ReactToPSR7Stream.php

Here tick() is called if on read there is no data. If I understand correctly, this is for loop not to block.

I use futureTick to queue read/write pipeline, eg:

public function tick()
{
    while (true) {
        $data = $this->input->read(self::BUFFER);
        if ('' === $data) {
            break;
        }

        // TODO: limit write rate
        $this->output->write($data);
    }

    if (!$this->input->eof()) {
        $this->queueTick();
        return;
    }
    $this->input->close();
    $this->output->close();
    call_user_func($this->result);
}

protected function queueTick()
{
    $this->loop->futureTick([$this, 'tick']);
}

Is this a correct way to implement PSR7->PSR7 pipeline?

from event-loop.

nick4fake avatar nick4fake commented on May 21, 2024

Another example:
https://github.com/WyriHaximus/ReactGuzzle/blob/master/src/HttpClientAdapter.php

What if we make a call inside a loop?

from event-loop.

clue avatar clue commented on May 21, 2024

Let's ping @WyriHaximus and let's see what he has to add 👍

from event-loop.

WyriHaximus avatar WyriHaximus commented on May 21, 2024

@nick4fake it's a horrible hack that I would not recomend 😞 , heck I strongly discourage of doing it when there are alternatives. It 'works' but only in most circumstances. That one in particular was made to provide a fully working PSR-7 stream. @clue made a much better way of doing that here. Another place I use it is here, but there I'm doing it because Guzzle uses some funky queue that I have to keep running in order for the adapter to work 😞 .

from event-loop.

clue avatar clue commented on May 21, 2024

@WyriHaximus thanks for giving some insight! What do you suggest we should do here? Is this something worth fixing or should we look into avoiding this altogether (is this even reasonable?)?

from event-loop.

clue avatar clue commented on May 21, 2024

I believe this has been superseded now that #72 is in and the tick() method has been removed 👍

I'm closing this for now, please feel free to come back with more details if this problem persists and we can reopen this 👍

from event-loop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.