1 /*******************************************************************************
2 
3     FiberSelectEvent 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.EventFDJobNotification;
16 
17 import ocean.io.select.client.FiberSelectEvent;
18 import ocean.io.select.fiber.SelectFiber;
19 import ocean.util.aio.DelegateJobNotification;
20 
21 /// ditto
22 class EventFDJobNotification: DelegateJobNotification
23 {
24     /***************************************************************************
25 
26         Constructor.
27 
28         Params:
29             event = FiberSelectEvent to synchronise on.
30 
31     ***************************************************************************/
32 
33     this (FiberSelectEvent event)
34     {
35         this.event = event;
36         super(&this.trigger, &this.wait);
37     }
38 
39     /***************************************************************************
40 
41         Constructor.
42 
43         Params:
44             fiber = Fiber to create FiberSelectEvent to synchronise on.
45 
46     ***************************************************************************/
47 
48     this (SelectFiber fiber)
49     {
50         this.event = new FiberSelectEvent(fiber);
51         super(&this.trigger, &this.wait);
52     }
53 
54     /***************************************************************************
55 
56         Changes the SelectFiber this handler is suspending
57 
58         Params:
59             fiber = new SelectFiber to suspend
60 
61     ***************************************************************************/
62 
63     public void setFiber (SelectFiber fiber)
64     {
65         this.event.fiber = fiber;
66     }
67 
68     /**************************************************************************
69 
70         Triggers the event.
71 
72     **************************************************************************/
73 
74     private void trigger ()
75     {
76         this.event.trigger();
77     }
78 
79     /**************************************************************************
80 
81         Waits on the event.
82 
83     **************************************************************************/
84 
85     private void wait ()
86     {
87         this.event.wait();
88     }
89 
90     /***************************************************************************
91 
92         FiberSelectEvent synchronise object.
93 
94     ***************************************************************************/
95 
96     private FiberSelectEvent event;
97 
98 }