Function consumeStreamWithLimit