paulcbetts/punchclock — pull request #1 by paulcbetts (2013-10-09 02:07:33+00:00)
Title: Test all the things

This PR adds some tests to verify the behavior of OperationQueue. In particular:

1. There should only ever be 'n' concurrent requests at a time.
1. Requests should be taken in priority order
1. Requests with the same key should be serialized (i.e. we should never have > 1 request with the key "Foo" concurrently)
1. Requests that *don't* have a key can run in parallel (i.e. we shouldn't serialize the "no key" key)

Since this is Rx, we detect whether "A request has been kicked off" via counting subscribers - the source Observable will only be subscribed to once we've started the operation.

## A Problematic Scenario

1. You have 'n' slots, they are partially or completely filled by *keyed* operations
1. You have several items queued up, they have different keys

In the ideal scenario, we would know that the slots being used by keyed items that are waiting in line "don't count", and that we should dequeue some more that possibly don't have key constraints. However, we are instead not that smart, and we end up possibly serializing work more than we need to.

There's no super easy way to solve this in the current design, so instead, we make it less likely by rigging the priority queue to always deliver non-keyed items before delivering keyed items, if it has the choice.

## Nobody will care

I'm pretty sure that people won't actually need keys anyways for like 99% of cases, so it probably won't actually matter. And you can always make > 1 instance of OperationQueue.