Skip to content

Commit

Permalink
Update signature to include Push in returned task
Browse files Browse the repository at this point in the history
  • Loading branch information
acupofjose committed May 22, 2024
1 parent 598643b commit 85249b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 3 additions & 2 deletions Realtime/Interfaces/IRealtimePresence.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Supabase.Realtime.Socket;
using System;
using System.Threading.Tasks;
using Supabase.Realtime.Channel;
using Supabase.Realtime.Models;
using static Supabase.Realtime.Constants;

Expand Down Expand Up @@ -40,14 +41,14 @@ public enum EventType
/// </summary>
/// <param name="payload"></param>
/// <param name="timeoutMs"></param>
Task Track(object? payload, int timeoutMs = DefaultTimeout);
Task<Push> Track(object? payload, int timeoutMs = DefaultTimeout);

/// <summary>
/// Untracks a client
/// </summary>
/// <param name="payload"></param>

Check warning on line 49 in Realtime/Interfaces/IRealtimePresence.cs

View workflow job for this annotation

GitHub Actions / build-and-test

XML comment has a param tag for 'payload', but there is no parameter by that name

Check warning on line 49 in Realtime/Interfaces/IRealtimePresence.cs

View workflow job for this annotation

GitHub Actions / build-and-test

XML comment has a param tag for 'payload', but there is no parameter by that name

Check warning on line 49 in Realtime/Interfaces/IRealtimePresence.cs

View workflow job for this annotation

GitHub Actions / build-and-test

XML comment has a param tag for 'payload', but there is no parameter by that name

Check warning on line 49 in Realtime/Interfaces/IRealtimePresence.cs

View workflow job for this annotation

GitHub Actions / build-and-deploy

XML comment has a param tag for 'payload', but there is no parameter by that name
/// <param name="timeoutMs"></param>

Check warning on line 50 in Realtime/Interfaces/IRealtimePresence.cs

View workflow job for this annotation

GitHub Actions / build-and-test

XML comment has a param tag for 'timeoutMs', but there is no parameter by that name

Check warning on line 50 in Realtime/Interfaces/IRealtimePresence.cs

View workflow job for this annotation

GitHub Actions / build-and-test

XML comment has a param tag for 'timeoutMs', but there is no parameter by that name

Check warning on line 50 in Realtime/Interfaces/IRealtimePresence.cs

View workflow job for this annotation

GitHub Actions / build-and-deploy

XML comment has a param tag for 'timeoutMs', but there is no parameter by that name
Task Untrack();
Task<Push> Untrack();

/// <summary>
/// Add a presence event handler
Expand Down
13 changes: 8 additions & 5 deletions Realtime/RealtimePresence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void TriggerDiff(SocketResponse response)
/// </summary>
/// <param name="payload"></param>
/// <param name="timeoutMs"></param>
public Task Track(object? payload, int timeoutMs = DefaultTimeout)
public Task<Push> Track(object? payload, int timeoutMs = DefaultTimeout)
{
var eventName = Core.Helpers.GetMappedToAttr(ChannelEventName.Presence).Mapping;
var push = new Push(_channel.Socket, _channel, eventName, "track",
Expand All @@ -169,7 +169,9 @@ void Handler(IRealtimePush<RealtimeChannel, SocketResponse> chanel, SocketRespon

push.OnTimeout += (sender, args) =>
{
tcs.SetException(new RealtimeException(args.ToString()) { Reason = FailureHint.Reason.PushTimeout });
if (sender is Push p)
tcs.SetException(new RealtimeException($"Failed to send push [{p.Ref}])")
{ Reason = FailureHint.Reason.PushTimeout });
};

_channel.Enqueue(push);
Expand All @@ -180,7 +182,7 @@ void Handler(IRealtimePush<RealtimeChannel, SocketResponse> chanel, SocketRespon
/// <summary>
/// Untracks an event.
/// </summary>
public Task Untrack()
public Task<Push> Untrack()
{
var eventName = Core.Helpers.GetMappedToAttr(ChannelEventName.Presence).Mapping;
var push = new Push(_channel.Socket, _channel, eventName, "untrack",
Expand All @@ -197,8 +199,9 @@ void Handler(IRealtimePush<RealtimeChannel, SocketResponse> chanel, SocketRespon

push.OnTimeout += (sender, args) =>
{
tcs.TrySetException(new RealtimeException((sender as Push)!.Ref)
{ Reason = FailureHint.Reason.PushTimeout });
if (sender is Push p)
tcs.TrySetException(new RealtimeException($"Failed to send push [{p.Ref}])")
{ Reason = FailureHint.Reason.PushTimeout });
};

_channel.Enqueue(push);
Expand Down

0 comments on commit 85249b0

Please sign in to comment.