lox/pheasant — pull request #69 by dhotson (2013-08-26 06:15:56+00:00)
Title: Async query support

Hi Lox,

This is a proof of concept for async queries.

Here's what it looks like in practice:

```php
// Set up an extra connection to do async stuff on
\Pheasant::instance()->connections()->addConnection('async1', $dsn);

$results = Animal::all()
->filter('!sleep(1)') // Pretend this query is slow (sleeps 1 second per row)
->async('async1')
;

// do some stuff in the meantime..

foreach ($results as $a) // Blocks until results are ready
var_dump($a->name);
```

Basically, I've added a `async` method to the `Collection` class to kick off a query in the background on a specific connection. It blocks when it needs the result.

The idea would be to have a small pool of connections available for doing queries in the background. It's currently all very explicit so that there's no surprises.

The test case I've included in this pull request demonstrates the feature quite well, it's able to do 3 seconds of work in PHP while two 3sec and 6sec mysql queries run in the background in parallel. the entire test case runs in 6sec rather than 12sec if it were to run sequentially.

Pretty neat huh? :-)