File tree Expand file tree Collapse file tree 2 files changed +17
-5
lines changed
Expand file tree Collapse file tree 2 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -38,15 +38,27 @@ namespace Core
3838 {
3939 this ->mChannelStatus = CHANNEL_STATUS::CLOSED;
4040 }
41+
42+ size_t size ()
43+ {
44+ return this ->mChannelData .size ();
45+ }
4146 template <typename T1>
4247 friend void operator <<(T1 &x, Channel<T1> &);
4348 };
4449
4550 template <typename T>
4651 void operator <<(T &x, Channel<T> &c)
4752 {
48- c.mChannelData .pop (x, true );
53+ if (c.mChannelStatus == CHANNEL_STATUS::OPEN)
54+ {
55+ if (!c.mChannelData .pop (x, true ))
56+ {
57+ // throw exception here
58+ }
59+ }
4960 }
61+
5062}
5163
5264#endif
Original file line number Diff line number Diff line change @@ -93,14 +93,14 @@ int main()
9393
9494 for (int i = 0 ; i < 1000000 ; i++)
9595 {
96- c << i ;
96+ c << rand () % 100 ;
9797 async ([&]()
9898 {
99- int x;
99+ int x ;
100100 x << c;
101- cout <<" Got from channel " << x << endl;
101+ cout <<" Got from channel " << x << " Channel size " << c. size ()<< endl;
102102 });
103- sleep ( 1 );
103+ usleep ( 1000 );
104104 }
105105 /*
106106 atexit(onExit);
You can’t perform that action at this time.
0 commit comments