multi threaded anime list requests

This commit is contained in:
Timon Ringwald 2022-08-21 21:23:38 +02:00
parent f5066d37f1
commit dc80a4a4fe
3 changed files with 5 additions and 6 deletions

View File

@ -5,7 +5,6 @@ import (
"git.milar.in/milarin/anilist" "git.milar.in/milarin/anilist"
"git.milar.in/milarin/channel" "git.milar.in/milarin/channel"
"git.milar.in/milarin/slices"
) )
type Pair[A, B any] struct { type Pair[A, B any] struct {
@ -29,7 +28,7 @@ func GetCurrentlyWatchingAnimes() (<-chan *anilist.MediaList, error) {
return nil, ErrAnimeListNotObtainable.Wrap(err, "access token acquisition failed") return nil, ErrAnimeListNotObtainable.Wrap(err, "access token acquisition failed")
} }
media := slices.Map(AnimeStatus, func(status anilist.MediaListStatus) <-chan *anilist.MediaList { media := channel.Map(channel.Of(AnimeStatus...), func(status anilist.MediaListStatus) <-chan *anilist.MediaList {
return anilist.NewApi(token).GetMediaList(context.Background(), anilist.MediaListQuery{ return anilist.NewApi(token).GetMediaList(context.Background(), anilist.MediaListQuery{
UserName: AnilistUsername, UserName: AnilistUsername,
Type: anilist.MediaTypeAnime, Type: anilist.MediaTypeAnime,
@ -37,7 +36,7 @@ func GetCurrentlyWatchingAnimes() (<-chan *anilist.MediaList, error) {
}, nil).Chan }, nil).Chan
}) })
return channel.Merge(media...), nil return channel.FlatChan(media), nil
} }
var ( var (

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.18
require ( require (
git.milar.in/milarin/adverr v1.0.0 git.milar.in/milarin/adverr v1.0.0
git.milar.in/milarin/anilist v1.5.0 git.milar.in/milarin/anilist v1.5.0
git.milar.in/milarin/channel v0.0.7 git.milar.in/milarin/channel v0.0.9
git.milar.in/milarin/envvars v1.0.3 git.milar.in/milarin/envvars v1.0.3
git.milar.in/milarin/gmath v0.0.2 git.milar.in/milarin/gmath v0.0.2
git.milar.in/milarin/slices v0.0.2 git.milar.in/milarin/slices v0.0.2

4
go.sum
View File

@ -2,8 +2,8 @@ git.milar.in/milarin/adverr v1.0.0 h1:9povP074PjpoZlNuiKPa9w6fDA8a4RSI5hEDo5T9Tq
git.milar.in/milarin/adverr v1.0.0/go.mod h1:wwfglcey4R3vqjNL/d8mbnvFJGzETRXzAEolIHZY32w= git.milar.in/milarin/adverr v1.0.0/go.mod h1:wwfglcey4R3vqjNL/d8mbnvFJGzETRXzAEolIHZY32w=
git.milar.in/milarin/anilist v1.5.0 h1:fSiAXY/topNk4ISEp2QtcG9HHKLJfMc8w05iqc+Paf0= git.milar.in/milarin/anilist v1.5.0 h1:fSiAXY/topNk4ISEp2QtcG9HHKLJfMc8w05iqc+Paf0=
git.milar.in/milarin/anilist v1.5.0/go.mod h1:8PTHXFMA45JpfRFIpcdrKwDHue8fbT/wwV1BuHFn6c0= git.milar.in/milarin/anilist v1.5.0/go.mod h1:8PTHXFMA45JpfRFIpcdrKwDHue8fbT/wwV1BuHFn6c0=
git.milar.in/milarin/channel v0.0.7 h1:cVKtwgH/EE7U+XTHcoFCClJ4LR349KanzjX9xKwRcNg= git.milar.in/milarin/channel v0.0.9 h1:vYJnXOaIn/+mng1+8CyepQgDfRse2s4FSLNc7zv85To=
git.milar.in/milarin/channel v0.0.7/go.mod h1:We83LTI8S7u7II3pD+A2ChCDWJfCkcBUCUqii9HjTtM= git.milar.in/milarin/channel v0.0.9/go.mod h1:We83LTI8S7u7II3pD+A2ChCDWJfCkcBUCUqii9HjTtM=
git.milar.in/milarin/envvars v1.0.3 h1:go6pYExUzPx+aLvJ5BKNkaANkBNmcrlRJ8TtWsk4uWY= git.milar.in/milarin/envvars v1.0.3 h1:go6pYExUzPx+aLvJ5BKNkaANkBNmcrlRJ8TtWsk4uWY=
git.milar.in/milarin/envvars v1.0.3/go.mod h1:rLh/HN6S254h6m2lklnImcpsy4kHFxaOjM6+Nv9GHKI= git.milar.in/milarin/envvars v1.0.3/go.mod h1:rLh/HN6S254h6m2lklnImcpsy4kHFxaOjM6+Nv9GHKI=
git.milar.in/milarin/gmath v0.0.2 h1:avz+75f8XqAYA1wEB6kis0R5xvRuepBKTqBuJBjh6Yw= git.milar.in/milarin/gmath v0.0.2 h1:avz+75f8XqAYA1wEB6kis0R5xvRuepBKTqBuJBjh6Yw=