Re: Creating a future/promise object

2015-07-14 Thread Frank Pagliughi via Digitalmars-d
The delegate could send a message to user code in another thread/fiber. In any case it removes a blocking get_result() and possibly the need for get_result_timeout(). That sounds interesting, and I will look into it. (Questions to follow, no doubt). But we've gone down a path at a specific s

Re: Creating a future/promise object

2015-07-08 Thread Sebastiaan Koppe via Digitalmars-d
On Tuesday, 7 July 2015 at 16:41:41 UTC, Frank Pagliughi wrote: Instead of pulling values out, have you considered pushing them? E.g. by supplying a delegate that gets called when the asynchronous action completed. I've always been on the fence about push vs pull when writing libraries of thi

Re: Creating a future/promise object

2015-07-07 Thread Frank Pagliughi via Digitalmars-d
It seems that just casting the Token (future) as "shared" to get it across the thread boundary works. From inside my thread: receive( (shared(Token) tok) { int res = do_something(); (cast(Token)tok).set_result(res); ... And then in the method which is exposed to the user

Re: Creating a future/promise object

2015-07-07 Thread Frank Pagliughi via Digitalmars-d
Instead of pulling values out, have you considered pushing them? E.g. by supplying a delegate that gets called when the asynchronous action completed. I've always been on the fence about push vs pull when writing libraries of this type. The callback/delegate method is probably more powerful a

Re: Creating a future/promise object

2015-07-07 Thread Sebastiaan Koppe via Digitalmars-d
On Monday, 6 July 2015 at 20:56:04 UTC, Frank Pagliughi wrote: void set_result(int retCode) { synchronized (mut) { this.retCode = retCode; completed = true; cond.notify(); } } int get_result() { synchronized (mut) { while (!completed)

Re: Creating a future/promise object

2015-07-07 Thread Frank Pagliughi via Digitalmars-d
Thanks for the replies! The parallelism Task is *doing* what I would like to do, but the package does not seem to expose the underlying components. The 'Task' essentially has a thread, future, and promise. I already have a long-running thread hidden inside of 'mything' which is serializing ac

Re: Creating a future/promise object

2015-07-06 Thread thedeemon via Digitalmars-d
On Monday, 6 July 2015 at 20:56:04 UTC, Frank Pagliughi wrote: void set_result(int retCode) { synchronized (mut) { this.retCode = retCode; completed = true; cond.notify(); } } int get_result() { synchronized (mut) { while (!completed)

Re: Creating a future/promise object

2015-07-06 Thread Justin Whear via Digitalmars-d
On Mon, 06 Jul 2015 20:56:03 +, Frank Pagliughi wrote: > Hello All, > > I'm trying to figure out how to create a shared object that can be used > to track asynchronous operations. Something that can be used like: > >Token tok = mything.start_something(); > >// do something else for

Creating a future/promise object

2015-07-06 Thread Frank Pagliughi via Digitalmars-d
Hello All, I'm trying to figure out how to create a shared object that can be used to track asynchronous operations. Something that can be used like: Token tok = mything.start_something(); // do something else for a while int n = tok.get_result(); // Block until result is ready The