On Mon, Feb 13, 2012 at 00:22, Mark Volkmann <[email protected]> wrote:
> Here's a snippet from the example code in the docs for the TLS module:
>
> var cleartextStream = tls.connect(8000, options, function() {
>   console.log('client connected',
>               cleartextStream.authorized ? 'authorized' : 'unauthorized');
>   process.stdin.pipe(cleartextStream);
>   process.stdin.resume();
> });
>
>
> Note how the callback function passed to tls.connect uses cleartextStream.
> That is returned from tls.connect.
> This seems unusual. Is it safe to assume that the callback will be invoked
> after the function returns?

Yes. It's an assumption that's true for everything that involves I/O.
The callback runs at the next tick of the event loop (or later) but
never at the current tick.

> I wonder why cleartextStream isn't just passed to the callback rather than
> being returned from tls.connect.

Because this === cleartextStream in your callback. The callback is
registered as a listener for cleartextStream's 'secureConnect' event
and listeners always run in the context of the emitting object.

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to