From d5fc5a1b93c9361c08d181a1cb4dca447e9edf84 Mon Sep 17 00:00:00 2001 From: "Diogo Franco (Kovensky)" Date: Fri, 26 Jul 2013 20:29:44 -0300 Subject: [PATCH] anidb: Make (*AniDB).User() try harder to return a user Will block for at least 2 seconds if the user ID is not cached. Any UDP API access will cache the user ID. --- anidb.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/anidb.go b/anidb.go index 7029a46..aa30395 100644 --- a/anidb.go +++ b/anidb.go @@ -41,8 +41,13 @@ func (adb *AniDB) User() *User { if adb.udp.user != nil { return adb.udp.user } else if adb.udp.credentials != nil { - // see if we can get it from the cache + // see if we can get it from the cache (we don't care if it's stale) adb.udp.user = UserByName(decrypt(adb.udp.credentials.username)) + if adb.udp.user != nil { + return adb.udp.user + } + // we have to go through the slow path + adb.udp.user = <-adb.GetUserByName(decrypt(adb.udp.credentials.username)) return adb.udp.user } } -- 2.44.0