Question: I have a piece of code in an `Action` that is querying a JS funtion.

Unfortunately I didn't make my registered action `async` at first and realized that the following code was stuck at the `InvokeAsync` line

```
async Task someCode() {
    string myRes = await jsRuntime.InvokeAsync<string>("MyMethod");
    Console.WriteLine(myCode); // <- this line was not reached!
}

public void myAction() {
    // synchronous here => how to convert it to synchronous code?!
    someCode.GetAwaiter().Result();
}

```

Because of this, the `WriteLine` part of code was not reached... Is there a proper way to call the `async` method here from the synchrounous method? Can anyone clarify why the following code works :

```
public async Task myAction() {
    await someCode;
}

```

Answer: 
You can use `depends_on` with a `condition`.

```yaml
services:
  backend:
    health_check: curl -fsS localhost:8080/ping || exit 1

  cypress:
    depends_on:
      backend:
        condition: service_healthy

```

It may also be sufficient to use the condition `service_started` which is equivalent to a depends on with no condition using the array syntax, afaik.

Some people are also doing it the brutal way by restarting until it suceeds.

```yaml
services:
  cypress:
    deploy:
      restart_policy:
        condition: on-failure
        delay: 10s
        max_attempts: 10

```

---

Personally, I think it's best if your services are able to boot even though a given dependency isn't up. They could retry to connect with exponential backoff and, until success, respond with something like a 503, for the endpoints that require this dependency.

Additionally, check for connectivity to said dependency in a readiness endpoint. In that case, some operating framework like Kubernetes could detect that the service isn't healthy.
Using `wait-for-it.sh` you can edit the timeout using the parameter `-t`

<https://github.com/vishnubob/wait-for-it/blob/master/README.md>