winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
4.77k stars 189 forks source link

can't use `sim.Resource` thats composing additional resources #6526

Open eladcon opened 1 month ago

eladcon commented 1 month ago

I tried this:

bring cloud;
bring sim;

class Backend impl sim.IResource {
  bucket: cloud.Bucket;
  new() {
    this.bucket = new cloud.Bucket();
  }

  pub inflight store(key: str, value: str) {
    this.bucket.put(key, value);
  }

  pub inflight onStop() {}
}

class Client {
  resource: sim.Resource;
  new() {
    let backend = new Backend();
    this.resource = new sim.Resource(inflight () => {
      return backend;
    });
  }

  pub inflight store(key: str, value: str) {
    this.resource.call("store", Json ["k1", "v1"]);
  }
}

let client = new Client();

test "store" {
  client.store("k1", "v1");
}

This happened:

[ERROR] store | Error: Missing environment variable: BUCKET_HANDLE_a2a9c469
[ERROR] store | Error: Resource is not running (it may have crashed or stopped)

I expected this:

No response

Is there a workaround?

No response

Anything else?

No response

Wing Version

No response

Node.js Version

No response

Platform(s)

No response

Community Notes