1 /*******************************************************************************
2 
3     Task suspend/resume interface for suspendable jobs waiting
4     for AsyncIO to finish.
5 
6     Copyright:
7         Copyright (c) 2018 dunnhumby Germany GmbH.
8         All rights reserved.
9 
10     License:
11         Boost Software License Version 1.0. See LICENSE.txt for details.
12 
13 *******************************************************************************/
14 
15 module ocean.util.aio.TaskJobNotification;
16 
17 import ocean.task.Task;
18 import ocean.task.util.Event;
19 import ocean.core.Verify;
20 import ocean.util.aio.DelegateJobNotification;
21 
22 /// ditto
23 class TaskJobNotification: DelegateJobNotification
24 {
25     /***************************************************************************
26 
27         Constructor.
28 
29     ***************************************************************************/
30 
31     this ()
32     {
33         this.task = Task.getThis();
34         super(&this.trigger, &this.wait);
35     }
36 
37     /**************************************************************************
38 
39         Triggers the event.
40 
41     **************************************************************************/
42 
43     private void trigger ()
44     {
45         this.event.trigger();
46     }
47 
48     /**************************************************************************
49 
50         Waits on the event.
51 
52     **************************************************************************/
53 
54     private void wait ()
55     {
56         this.event.wait();
57     }
58 
59     /**************************************************************************
60 
61         Resets the notification to a current task.
62 
63     **************************************************************************/
64 
65     public void reset ()
66     {
67         this.task = Task.getThis();
68     }
69 
70     /**************************************************************************
71 
72         Task to be resumed.
73 
74     **************************************************************************/
75 
76     private Task task;
77 
78     /**************************************************************************
79 
80         TaskTriggerEvent used to resume a task.
81 
82     **************************************************************************/
83 
84     private TaskEvent event;
85 }