Documented some more possible design changes to the request framework; Waitable now manages the list of 'Ended' event subscribers itself and triggers the callback if the Waitable instance had already ended at the time of subscription

git-svn-id: file:///srv/devel/repo-conversion/nusu@76 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2008-06-05 19:26:36 +00:00
parent e0cf91a0a4
commit 26365177dd
2 changed files with 173 additions and 23 deletions

View file

@ -64,5 +64,97 @@ Design using interfaces:
interface IThreadedRequest : IRequest, IThreadedWaitable { }
interface IThreadedRequest<ResultType> :
IRequest<ResultType>, IThreadedRequest, IThreadedWaitable { }
interface IThreadedRequest<ResultType> : IRequest<ResultType>, IThreadedRequest { }
Impossible implementation:
class Request : IRequest {
event EventHandler Finished;
void Wait();
bool Wait(int timeoutMilliseconds);
bool Finished { get; }
void Join();
protected virtual void ReraiseExceptions() { }
}
class Request<ResultType> : Request, IRequest<ResultType> {
new ResultType Join();
protected abstract ResultType GatherResults();
}
Do not provide: (see conflict in second version)
class ThreadedRequest : Request, IThreadedRequest {
WaitHandle WaitHandle { get; }
}
class ThreadedRequest<ResultType> : ThreadedRequest, Request<ResultType> { }
// However, not providing these, the user would have to rewrite
// the complex threading routines everywhere he uses then. Bad.
Inelegant implementation:
class Void {}
class Request<ResultType> : IRequest<ResultType> {
new ResultType Join();
protected abstract ResultType GatherResults();
}
class ThreadedRequest<ResultType> : Request<ResultType> { }
// However, not providing these, the user would have to rewrite
// the complex threading routines everywhere he uses then. Bad.
Maybe keeping threaded and non-threaded requests apart is a good thing?
IWaitable (without Finished event)
Waitable (Finished event)
Request
Request<Bla>
IWaitable (without Finished event)
ThreadedWaitable (AsyncFinished event)
ThreadedRequest
ThreadedRequest<Bla>
Or just dump the WaitHandle schmonder
Waitable (with virtual protected SyncRoot { get { return this; } })
Request
Request<Bla>
LazyWaitHandle
WaitHandle Get(Waitable waitable)
Or use policy classes (waithandle trouble)
Waitable
Request
Request<Bla>
RequestImpl<ThreadPolicy>
RequestImpl<Bla, ThreadPolicy>
LazyWaitHandle
WaitHandle Get(Waitable waitable)
WaitHandle Get(Waitable waitable, object syncRoot)
ThreadPolicy {
virtual void lock() {}
virtual void unlock() {}
}