From: Diogo Franco (Kovensky) Date: Fri, 26 Jul 2013 23:29:44 +0000 (-0300) Subject: anidb: Make (*AniDB).User() try harder to return a user X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=d5fc5a1b93c9361c08d181a1cb4dca447e9edf84;p=go-anidb.git 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. --- 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 } }