Changed the stream closing API to return a promise for the total length.

The old closing protocol had a race condition. The stream appeared to be closed sometime after close was called, whether or not all the pre-close elements had already been gotten. This changes the indication of closedness to be a promise for the overall length of the queue. This enables clients to do some flow control, bounding the extent of their read-ahead, if they wish.