Giter Site home page Giter Site logo

Work on req as well as res about on-finished HOT 9 CLOSED

jshttp avatar jshttp commented on September 17, 2024
Work on req as well as res

from on-finished.

Comments (9)

jonathanong avatar jonathanong commented on September 17, 2024

meh not a big deal. ideally, it should only check for res. it may work for requests and req but i haven't tested that yet

from on-finished.

dougwilson avatar dougwilson commented on September 17, 2024

Only accepting res is the only good way to do #4, which is why I ask. If you read the internal implementation of req and res, you'll see what I mean.

from on-finished.

dougwilson avatar dougwilson commented on September 17, 2024

it may work for requests and req but i haven't tested that yet

it does work, because this modules does thingie.res, which translates to req.res, and thus works, weirdly.

from on-finished.

jonathanong avatar jonathanong commented on September 17, 2024

hmmm i guess it doesn't then because you want to listen to finish on the req:

var req = http.request({
  method: 'POST',
  path: '/upload'
})

var stream = fs.createReadStream('filename')
stream.pipe(req)

finished(req, function () {
  stream.destroy()
})

from on-finished.

dougwilson avatar dougwilson commented on September 17, 2024

Right. This module, as it is right now, only allows you to act when the response is finished. AFAIK this will also mean the request is finished, but I'm not sure. But you cannot actually pass in req, since it'll just add all the listeners on res anyway...

from on-finished.

dougwilson avatar dougwilson commented on September 17, 2024

I first noticed this because I couldn't use finished with body-parser, since it wouldn't fire until after the response was finished, but I wanted something that would first after the req was finished.

Does it seem desirable that we wait for whatever is passed in to finish, instead of switching to an existing res property? This would mean koa cannot pass in the ctx variable directly, it would need to change to do ctx.res.

from on-finished.

jonathanong avatar jonathanong commented on September 17, 2024

Does it seem desirable that we wait for whatever is passed in to finish, instead of switching to an existing res property?

ya

from on-finished.

dougwilson avatar dougwilson commented on September 17, 2024

It looks like if this were changed, the koa example would become:

function* () {
  var stream = this.body = fs.createReadStream('thingie.json')
  onFinished(this.res, function (err) {
    stream.destroy()
  })
}

i.e. this -> this.res

from on-finished.

jonathanong avatar jonathanong commented on September 17, 2024

yeah that's fine

from on-finished.

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.