From 35f83c515b75cc17c386aeb4ddcfcbd21af9da84 Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Sat, 5 Apr 2025 16:27:13 +0530 Subject: [PATCH] Replace Promise with Fuse. (#3580) --- pkg/rtc/participant.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/rtc/participant.go b/pkg/rtc/participant.go index a25e4b244..725185789 100644 --- a/pkg/rtc/participant.go +++ b/pkg/rtc/participant.go @@ -24,6 +24,7 @@ import ( "sync" "time" + "github.com/frostbyte73/core" lru "github.com/hashicorp/golang-lru/v2" "github.com/pion/rtcp" "github.com/pion/sdp/v3" @@ -245,8 +246,8 @@ type ParticipantImpl struct { onDataMessage func(types.LocalParticipant, []byte) onMetrics func(types.Participant, *livekit.DataPacket) - migrateState atomic.Value // types.MigrateState - migratedTracksPublishedPromise *utils.Promise[bool] + migrateState atomic.Value // types.MigrateState + migratedTracksPublishedFuse core.Fuse onClose func(types.LocalParticipant) onClaimsChanged func(participant types.LocalParticipant) @@ -308,9 +309,8 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) { p.timedVersion.Update(params.VersionGenerator.Next()) p.migrateState.Store(types.MigrateStateInit) - p.migratedTracksPublishedPromise = utils.NewPromise[bool]() if !p.params.Migration { - p.migratedTracksPublishedPromise.Resolve(true, nil) + p.migratedTracksPublishedFuse.Break() } p.state.Store(livekit.ParticipantInfo_JOINING) @@ -1264,7 +1264,7 @@ func (p *ParticipantImpl) SetMigrateState(s types.MigrateState) { // re-resolve to check if the track is still active and unsubscribe if none // is active, as local track is in the process of completing publish, // the check would have resolved to an empty track leading to unsubscription. - <-p.migratedTracksPublishedPromise.Done() + <-p.migratedTracksPublishedFuse.Watch() } if onMigrateStateChange := p.getOnMigrateStateChange(); onMigrateStateChange != nil { @@ -2719,8 +2719,8 @@ func (p *ParticipantImpl) handleTrackPublished(track types.MediaTrack, isMigrate delete(p.pendingPublishingTracks, track.ID()) p.pendingTracksLock.Unlock() - if !p.hasPendingMigratedTrack() && !p.migratedTracksPublishedPromise.Resolved() { - p.migratedTracksPublishedPromise.Resolve(true, nil) + if !p.hasPendingMigratedTrack() { + p.migratedTracksPublishedFuse.Break() } }