Skip to content
Snippets Groups Projects
Select Git revision
  • 6cec75481e99a5cbcc1c39ffc7981e19aeaa6e49
  • release default protected
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • hotfix/TestHostPool_UpdateNdf_AddFilter
  • XX-4719/announcementChannels
  • xx-4717/logLevel
  • jonah/noob-channel
  • master protected
  • XX-4707/tagDiskJson
  • xx-4698/notification-retry
  • hotfix/notifylockup
  • syncNodes
  • hotfix/localCB
  • XX-4677/NewChanManagerMobile
  • XX-4689/DmSync
  • duplicatePrefix
  • XX-4601/HavenInvites
  • finalizedUICallbacks
  • XX-4673/AdminKeySync
  • debugNotifID
  • anne/test
  • v4.7.5
  • v4.7.4
  • v4.7.3
  • v4.7.2
  • v4.7.1
  • v4.6.3
  • v4.6.1
  • v4.5.0
  • v4.4.4
  • v4.3.11
  • v4.3.8
  • v4.3.7
  • v4.3.6
  • v4.3.5
  • v4.2.0
  • v4.3.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
41 results

delayedTimer.go

Blame
  • delayedTimer.go 1.56 KiB
    ////////////////////////////////////////////////////////////////////////////////
    // Copyright © 2020 xx network SEZC                                           //
    //                                                                            //
    // Use of this source code is governed by a license that can be found in the  //
    // LICENSE file                                                               //
    ////////////////////////////////////////////////////////////////////////////////
    
    package fileTransfer
    
    import "time"
    
    // The DelayedTimer type represents a single event manually started.
    // When the DelayedTimer expires, the current time will be sent on C.
    // A DelayedTimer must be created with NewDelayedTimer.
    type DelayedTimer struct {
    	d time.Duration
    	t *time.Timer
    	C *<-chan time.Time
    }
    
    // NewDelayedTimer creates a new DelayedTimer that will send the current time on
    // its channel after at least duration d once it is started.
    func NewDelayedTimer(d time.Duration) *DelayedTimer {
    	c := make(<-chan time.Time)
    	return &DelayedTimer{
    		d: d,
    		C: &c,
    	}
    }
    
    // Start starts the timer that will send the current time on its channel after
    // at least duration d. If it is already running or stopped, it does nothing.
    func (dt *DelayedTimer) Start() {
    	if dt.t == nil {
    		dt.t = time.NewTimer(dt.d)
    		dt.C = &dt.t.C
    	}
    }
    
    // Stop prevents the Timer from firing.
    // It returns true if the call stops the timer, false if the timer has already
    // expired, been stopped, or was never started.
    func (dt *DelayedTimer) Stop() bool {
    	if dt.t == nil {
    		return false
    	}
    
    	return dt.t.Stop()
    }