1

I'm wondering if someone could guide me in the right direction for creating a synchronous queue of requests to a server that requires this pattern.

I would like to keep using the already implemented async/await pattern in my code and also be able to enqueue both GET and POST requests that are generic in both upload parameters as well as downloaded result (which will be serialized with JSON).

Any suggestions?

svick
  • 236,525
  • 50
  • 385
  • 514
  • Could you explain what you want in more detail? Why do you need a synchronous queue? What does it mean to “keep using the already implemented async/await pattern”? – svick Dec 14 '12 at 22:23

3 Answers3

0

I recommend using ActionBlock<T> from the TPL Dataflow library.

Alternatively, you could use AsyncProducerConsumerQueue from my AsyncEx library.

Stephen Cleary
  • 437,863
  • 77
  • 675
  • 810
0

Your client code may be async while your service is purely synchronous. You may set ServiceBehaviorAttribute so your service performs one request after the other. It even can run on the same thread that you used to open the servicehost. If your service never executes an 'await' it runs synchronous. Using this design you can enhance your service when needed without breaking the client. See my post for some hints.

Community
  • 1
  • 1
Stefan Forster
  • 405
  • 4
  • 7
0

Just use a lock if you require single-threaded access. There is an async equivalent for this: AsyncLock (or AsyncSemaphore).

No need for complex constructs like queues or data-flow. (AsyncSemaphore has one such queue under the hood, but that doesn't matter to you).

usr
  • 168,620
  • 35
  • 240
  • 369