Skip to content

Commit da666bd

Browse files
author
Vishnu Vijayan
committed
Channel added
1 parent 28cc64e commit da666bd

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

core/include/Channel.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff 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

main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)