Add wait-for-sbot to peach-config #131
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "wait-for-sbot"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
As discussed here, this PR adds a wait-for-sbot function peach-config.
It tries to connect to sbot and call whoami, and if it successfully returns, then it returns a success, and we know the sbot is ready for connections.
If whoami fails, it waits two seconds, and then tries again. I tries a maximum of 10 times, and then it gives up and returns an error.
hi @notplants, here from the "P4P Rust Learning" chat. 😺
on how to refactor
peach-config/src/wait_for_sbot.rs
, here's what i came up with so far:changes i made:
sbot_is_running
and instead used abreak
to exit the loopsbot_is_running
, shouldn't this have been abool
? i'm not sure if there's a reason for this to be an integer, when it seems like1
is being used astrue
and0
is being used asfalse
.max_num_attempts
to be a static constanttwo_seconds
to be namedsleep_duration
, might be a personal preference but imo the variable name should describe the purpose of what's in the container. so later when you wanna change how many seconds, you don't need to change that it's asleep_duration
.i'm curious, what bothers you about
match
?another approach (an alternative to the
while
loop) would be to use recusive functions, but i'm still not sure how to do that withoutmatch
.if you plan to unwrap both cases (Ok and Err), afaik
match
is great for this. if you only want to unwrap Ok, then i'd use anif let
. mayyybeee there's a way to do this with theResult
methods?anyways, i hope this helped, happy to review pull requests anytime. 💜
for comparison, if we use ditch the
Err
cases and then useif let
instead ofmatch
:thanks @ahdinosaur ! much appreciated. I will comment in more detail later, but I've learned a bunch from these comments :)
nice to have clarity on when to use this, that makes sense!
cool, I didn't realize there was a break in rust. yes bool seems preferable, and removing all together to use break even better
👍
👍
there were some cases elsewhere where I was able to replace nested match statements with maps and transforms (the Result and Option methods), which made the code more concise and clear
so I don't specifically want to avoid match statements, but I found the nested match statements can get kind of deep and unwieldy.
I'm also not sure how to use the result methods within this specific while loop context, but using a mutable variable, and is_some() seems like an interesting pattern for doing things sequentially instead of in an ever-deepening nested match