cache2go icon indicating copy to clipboard operation
cache2go copied to clipboard

AfterFunc with go

Open learnergo opened this issue 6 years ago • 4 comments

if smallestDuration > 0 {
		table.cleanupTimer = time.AfterFunc(smallestDuration, func() {
			go table.expirationCheck()
		})
}

AfterFunc creates a new goroute.Is it necessary to use 'go' in 'AfterFunc'

learnergo avatar Dec 19 '18 11:12 learnergo

I think it's preferred because otherwise cleaning up the table (which can be a costly routine) would block the caller.

muesli avatar Dec 19 '18 11:12 muesli

I think "go" should be here:

if item.lifeSpan > 0 && (expDur == 0 || item.lifeSpan < expDur) {
		go table.expirationCheck()
}

learnergo avatar Dec 20 '18 07:12 learnergo

I think "go" should be here:

if item.lifeSpan > 0 && (expDur == 0 || item.lifeSpan < expDur) {
		go table.expirationCheck()
}

it will run more times, not just run once for smallestDuration

Nassue avatar Feb 18 '19 07:02 Nassue

I think "go" should be here:

if item.lifeSpan > 0 && (expDur == 0 || item.lifeSpan < expDur) {
		go table.expirationCheck()
}

it will run more times, not just run once for smallestDuration

??

learnergo avatar Feb 18 '19 07:02 learnergo