Created
October 6, 2021 18:17
-
-
Save viggin543/3eea24b59f5cd38d9b35de8882d5a4c0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func (this *usersService) IsMagicLinkVerified(ctx context.Context, in *users.IsMagicLinkVerifiedRequest) (*users.IsMagicLinkVerifiedResponse, error) { | |
| c, _ := context.WithDeadline(ctx, time.Now().Add(25*time.Second)) | |
| ticker := ImmediateTicker(c, time.Second) | |
| for { | |
| select { | |
| case <-c.Done(): | |
| return &users.IsMagicLinkVerifiedResponse{Status: users.MagicLinkStatus_unknown}, nil | |
| case <-ticker: | |
| status, token := this.tokensRepo.IsMagicLinkVerified(in.SessionId) | |
| if status != users.MagicLinkStatus_unknown { | |
| return &users.IsMagicLinkVerifiedResponse{ | |
| Status: status, | |
| Token: token, | |
| }, nil | |
| } | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a couple of interesting points
Notice, no Promises or Futures or any multi-threading communication.
this is 100% async, every time the goroutine is awaiting ( say between the ticks ) No thread is blocked.
I think this is super cool !