Skip to content

Commit

Permalink
fix: protect callbacks against failures (#11)
Browse files Browse the repository at this point in the history
Co-authored-by: Mitch Freed <[email protected]>
  • Loading branch information
msfreed and mitch-wilqo authored Jan 20, 2024
1 parent e604b74 commit 7818a16
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Casbin.Watcher.Redis/Casbin.Watcher.Redis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<ItemGroup>
<PackageReference Include="Casbin.NET" Version="2.1.1" />
<PackageReference Include="StackExchange.Redis" Version="2.7.17" />
<PackageReference Include="System.Text.Json" Version="8.0.1" />
<PackageReference Include="System.Text.Json" Version="8.0.1" Condition="'$(TargetFramework)'=='netstandard2.1'" />
</ItemGroup>

<ItemGroup>
Expand Down
32 changes: 20 additions & 12 deletions Casbin.Watcher.Redis/RedisWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,18 @@ private void Subscribe()
var isSelf = message.Id == Id;
if (!(isSelf && _options.IgnoreSelf))
{
if (_callbackWithMessage != null)
try
{
_callbackWithMessage.Invoke(message);
}
else
{
_callback?.Invoke();
if (_callbackWithMessage != null)
{
_callbackWithMessage.Invoke(message);
}
else
{
_callback?.Invoke();
}
}
catch {}
}
});
}
Expand All @@ -170,14 +174,18 @@ private void SubscribeAsync()
var isSelf = message.Id == Id;
if (!(isSelf && _options.IgnoreSelf))
{
if (_asyncCallbackWithMessage != null)
{
_asyncCallbackWithMessage.Invoke(message);
}
else
try
{
_asyncCallback?.Invoke();
if (_asyncCallbackWithMessage != null)
{
_asyncCallbackWithMessage.Invoke(message);
}
else
{
_asyncCallback?.Invoke();
}
}
catch {}
}
});
}
Expand Down

0 comments on commit 7818a16

Please sign in to comment.