Replace Promise with Fuse. (#3580)
This commit is contained in:
@@ -24,6 +24,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/frostbyte73/core"
|
||||||
lru "github.com/hashicorp/golang-lru/v2"
|
lru "github.com/hashicorp/golang-lru/v2"
|
||||||
"github.com/pion/rtcp"
|
"github.com/pion/rtcp"
|
||||||
"github.com/pion/sdp/v3"
|
"github.com/pion/sdp/v3"
|
||||||
@@ -245,8 +246,8 @@ type ParticipantImpl struct {
|
|||||||
onDataMessage func(types.LocalParticipant, []byte)
|
onDataMessage func(types.LocalParticipant, []byte)
|
||||||
onMetrics func(types.Participant, *livekit.DataPacket)
|
onMetrics func(types.Participant, *livekit.DataPacket)
|
||||||
|
|
||||||
migrateState atomic.Value // types.MigrateState
|
migrateState atomic.Value // types.MigrateState
|
||||||
migratedTracksPublishedPromise *utils.Promise[bool]
|
migratedTracksPublishedFuse core.Fuse
|
||||||
|
|
||||||
onClose func(types.LocalParticipant)
|
onClose func(types.LocalParticipant)
|
||||||
onClaimsChanged func(participant types.LocalParticipant)
|
onClaimsChanged func(participant types.LocalParticipant)
|
||||||
@@ -308,9 +309,8 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
|||||||
p.timedVersion.Update(params.VersionGenerator.Next())
|
p.timedVersion.Update(params.VersionGenerator.Next())
|
||||||
|
|
||||||
p.migrateState.Store(types.MigrateStateInit)
|
p.migrateState.Store(types.MigrateStateInit)
|
||||||
p.migratedTracksPublishedPromise = utils.NewPromise[bool]()
|
|
||||||
if !p.params.Migration {
|
if !p.params.Migration {
|
||||||
p.migratedTracksPublishedPromise.Resolve(true, nil)
|
p.migratedTracksPublishedFuse.Break()
|
||||||
}
|
}
|
||||||
|
|
||||||
p.state.Store(livekit.ParticipantInfo_JOINING)
|
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
|
// 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,
|
// is active, as local track is in the process of completing publish,
|
||||||
// the check would have resolved to an empty track leading to unsubscription.
|
// the check would have resolved to an empty track leading to unsubscription.
|
||||||
<-p.migratedTracksPublishedPromise.Done()
|
<-p.migratedTracksPublishedFuse.Watch()
|
||||||
}
|
}
|
||||||
|
|
||||||
if onMigrateStateChange := p.getOnMigrateStateChange(); onMigrateStateChange != nil {
|
if onMigrateStateChange := p.getOnMigrateStateChange(); onMigrateStateChange != nil {
|
||||||
@@ -2719,8 +2719,8 @@ func (p *ParticipantImpl) handleTrackPublished(track types.MediaTrack, isMigrate
|
|||||||
delete(p.pendingPublishingTracks, track.ID())
|
delete(p.pendingPublishingTracks, track.ID())
|
||||||
p.pendingTracksLock.Unlock()
|
p.pendingTracksLock.Unlock()
|
||||||
|
|
||||||
if !p.hasPendingMigratedTrack() && !p.migratedTracksPublishedPromise.Resolved() {
|
if !p.hasPendingMigratedTrack() {
|
||||||
p.migratedTracksPublishedPromise.Resolve(true, nil)
|
p.migratedTracksPublishedFuse.Break()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user