Code Monkey home page Code Monkey logo

Comments (8)

hemantjp avatar hemantjp commented on May 19, 2024 1

@clue thank you sir. i was mislead thinking that close event needed an argument. it should have dawned on me it didnt need one

from http-client.

clue avatar clue commented on May 19, 2024

HI @hemantjp, I'm not sure I quite follow what your issue is. In case you want to apply a timeout to a pending request, have you seen #104 (comment)?

If your problem persists, can you give a short gist to reproduce the problem you're seeing and/or provide a more detailed exception trace?

from http-client.

hemantjp avatar hemantjp commented on May 19, 2024

@clue , i have already referred to #104 . The close event of the request is not getting the proper arguments. i have passed it an exception class but it is saying none supplied.
attached is almost the complete stacktrace.

could this be an issue because i am using php7?

Should i provide more details?

from http-client.

clue avatar clue commented on May 19, 2024

The close event of the request is not getting the proper arguments. i have passed it an exception class but it is saying none supplied.

The Request implements WritableStreamInterface, so its documentation also applies (https://github.com/reactphp/stream#writablestreaminterface): The close event does not receive any arguments! You should probably use the error event in this case, which will report an Exception as per the above documentation.

I hope this helps 👍

I believe this has been answered, so I'm closing this for now. Please come back with more details if this problem persists and we can reopen this 👍

from http-client.

hemantjp avatar hemantjp commented on May 19, 2024

@clue the error event does not get triggered when i forcibly close the request.
Any suggestion as to how to trigger the promise reject.
i need to handle it down stream on a forcible timeout event.

from http-client.

clue avatar clue commented on May 19, 2024

the error event does not get triggered when i forcibly close the request.
Any suggestion as to how to trigger the promise reject.

Yes, explicitly calling close() will only emit the close event, not the error event. This is expected behavior. What promise are you referring to here? This API does not use promises right now (#41).

from http-client.

hemantjp avatar hemantjp commented on May 19, 2024

@clue Referring to the deferred object i have created to maintain promise like feel.

public function call()
    {
        $this->request = $this->client->request($this->method, $this->url);
/* this deferred object*/
        $deferred = new Deferred();
        $this->request->on('response', function (\React\HttpClient\Response $response)use ($deferred) {
            $response->on('data', function ($chunk) use ($deferred){
                    $deferred->resolve($chunk);
            });
        });
        $this->request->on('error', function (\Exception $e) use ($deferred){
            $deferred->reject($e->getMessage());
        });

Error thrown here
        // $this->request->on('close', function (\Exception $e) use ($deferred){
        //    $deferred->reject($e->getMessage());
        // });
        
        $this->request->end();
        return $deferred->promise();
    }

    public function close(){
        $this->request->close();
    }

from http-client.

clue avatar clue commented on May 19, 2024

Your API seems to suffer from a number of flaws, e.g. it looks like your API is subject to a temporal dependence. If you explicitly call your close() method, you could as well access your Deferred to explicitly reject() it. As an alternative, you may register to the close event and just reject() with a generic error there.

from http-client.

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.