Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
StackExchange.Redis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
StackExchange.Redis
Commits
86ee27f4
Commit
86ee27f4
authored
Jul 06, 2018
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shave some yaks on ChannelMessageQueue
parent
fa123558
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
4 deletions
+44
-4
ChannelMessageQueue.cs
...Exchange.Redis/StackExchange/Redis/ChannelMessageQueue.cs
+44
-4
No files found.
StackExchange.Redis/StackExchange/Redis/ChannelMessageQueue.cs
View file @
86ee27f4
using
System
;
using
System
;
using
System.Reflection
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Channels
;
using
System.Threading.Channels
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
...
@@ -10,6 +11,20 @@ namespace StackExchange.Redis
...
@@ -10,6 +11,20 @@ namespace StackExchange.Redis
/// </summary>
/// </summary>
public
readonly
struct
ChannelMessage
public
readonly
struct
ChannelMessage
{
{
/// <summary>
/// See Object.ToString
/// </summary>
public
override
string
ToString
()
=>
((
string
)
Channel
)
+
":"
+
((
string
)
Value
);
/// <summary>
/// See Object.GetHashCode
/// </summary>
public
override
int
GetHashCode
()
=>
Channel
.
GetHashCode
()
^
Value
.
GetHashCode
();
/// <summary>
/// See Object.Equals
/// </summary>
public
override
bool
Equals
(
object
obj
)
=>
obj
is
ChannelMessage
cm
&&
cm
.
Channel
==
Channel
&&
cm
.
Value
==
Value
;
internal
ChannelMessage
(
RedisChannel
channel
,
RedisValue
value
)
internal
ChannelMessage
(
RedisChannel
channel
,
RedisValue
value
)
{
{
Channel
=
channel
;
Channel
=
channel
;
...
@@ -37,6 +52,11 @@ public sealed class ChannelMessageQueue
...
@@ -37,6 +52,11 @@ public sealed class ChannelMessageQueue
private
readonly
RedisChannel
_redisChannel
;
private
readonly
RedisChannel
_redisChannel
;
private
RedisSubscriber
_parent
;
private
RedisSubscriber
_parent
;
/// <summary>
/// See Object.ToString
/// </summary>
public
override
string
ToString
()
=>
(
string
)
_redisChannel
;
/// <summary>
/// <summary>
/// Indicates if all messages that will be received have been drained from this channel
/// Indicates if all messages that will be received have been drained from this channel
/// </summary>
/// </summary>
...
@@ -84,6 +104,26 @@ public ValueTask<ChannelMessage> ReadAsync(CancellationToken cancellationToken =
...
@@ -84,6 +104,26 @@ public ValueTask<ChannelMessage> ReadAsync(CancellationToken cancellationToken =
/// </summary>
/// </summary>
public
bool
TryRead
(
out
ChannelMessage
item
)
=>
_channel
.
Reader
.
TryRead
(
out
item
);
public
bool
TryRead
(
out
ChannelMessage
item
)
=>
_channel
.
Reader
.
TryRead
(
out
item
);
/// <summary>
/// Attempt to query the backlog length of the queue
/// </summary>
public
bool
TryGetCount
(
out
int
count
)
{
// get this using the reflection
try
{
var
prop
=
_channel
.
GetType
().
GetProperty
(
"ItemsCountForDebugger"
,
BindingFlags
.
Instance
|
BindingFlags
.
NonPublic
);
if
(
prop
!=
null
)
{
count
=
(
int
)
prop
.
GetValue
(
_channel
);
return
true
;
}
}
catch
{
}
count
=
default
;
return
false
;
}
private
Delegate
_onMessageHandler
;
private
Delegate
_onMessageHandler
;
private
void
AssertOnMessage
(
Delegate
handler
)
private
void
AssertOnMessage
(
Delegate
handler
)
{
{
...
@@ -107,7 +147,7 @@ private async void OnMessageSyncImpl()
...
@@ -107,7 +147,7 @@ private async void OnMessageSyncImpl()
while
(!
IsCompleted
)
while
(!
IsCompleted
)
{
{
ChannelMessage
next
;
ChannelMessage
next
;
try
{
if
(!
TryRead
(
out
next
))
next
=
await
ReadAsync
(
);
}
try
{
if
(!
TryRead
(
out
next
))
next
=
await
ReadAsync
().
ConfigureAwait
(
false
);
}
catch
(
ChannelClosedException
)
{
break
;
}
// expected
catch
(
ChannelClosedException
)
{
break
;
}
// expected
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
...
@@ -136,7 +176,7 @@ private async void OnMessageAsyncImpl()
...
@@ -136,7 +176,7 @@ private async void OnMessageAsyncImpl()
while
(!
IsCompleted
)
while
(!
IsCompleted
)
{
{
ChannelMessage
next
;
ChannelMessage
next
;
try
{
if
(!
TryRead
(
out
next
))
next
=
await
ReadAsync
();
}
try
{
if
(!
TryRead
(
out
next
))
next
=
await
ReadAsync
()
.
ConfigureAwait
(
false
)
;
}
catch
(
ChannelClosedException
)
{
break
;
}
// expected
catch
(
ChannelClosedException
)
{
break
;
}
// expected
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
...
@@ -147,7 +187,7 @@ private async void OnMessageAsyncImpl()
...
@@ -147,7 +187,7 @@ private async void OnMessageAsyncImpl()
try
try
{
{
var
task
=
handler
.
Invoke
(
next
.
Channel
,
next
.
Value
);
var
task
=
handler
.
Invoke
(
next
.
Channel
,
next
.
Value
);
if
(
task
!=
null
)
await
task
;
if
(
task
!=
null
)
await
task
.
ConfigureAwait
(
false
)
;
}
}
catch
{
}
// matches MessageCompletable
catch
{
}
// matches MessageCompletable
}
}
...
@@ -167,7 +207,7 @@ internal async Task UnsubscribeAsyncImpl(Exception error = null, CommandFlags fl
...
@@ -167,7 +207,7 @@ internal async Task UnsubscribeAsyncImpl(Exception error = null, CommandFlags fl
var
parent
=
_parent
;
var
parent
=
_parent
;
if
(
parent
!=
null
)
if
(
parent
!=
null
)
{
{
await
parent
.
UnsubscribeAsync
(
_redisChannel
,
HandleMessage
,
flags
);
await
parent
.
UnsubscribeAsync
(
_redisChannel
,
HandleMessage
,
flags
)
.
ConfigureAwait
(
false
)
;
_parent
=
null
;
_parent
=
null
;
_channel
.
Writer
.
TryComplete
(
error
);
_channel
.
Writer
.
TryComplete
(
error
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment