Domanda

I'm reading the following tutorial on Twisted: Tutorial

I've a question regarding what I read in this section:

It says in the tutorial that

Transports represents a single connection that can send and/or receive bytes.

It later said that

If you scan the methods defined for ITransport, you won’t find any for receiving data. That’s because Transports always handle the low-level details of reading data asynchronously from their connections, and give the data to us via callbacks

What does the latter mean? Why aren't there any methods for receiving data?

È stato utile?

Soluzione

The use of callbacks is referred to (tongue-in-cheek) as the Hollywood Principle: "Don't call us, we'll call you." Instead of calling a method to receive data, you register a function that you want to be called when data is available, which is referred to as a callback function or just a callback.

Altri suggerimenti

A callback is a function which is invoked when the asynchronous activity is finished or ready to notify of some progress. The documentation is describing a behavior in which the creator/caller of something using an ITransport doesn't have to ask for data and wait around doing nothing.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top