Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: capture reassignable variable and mutable objects #3064

Merged
merged 16 commits into from
Jun 26, 2023

Conversation

ekeren
Copy link
Collaborator

@ekeren ekeren commented Jun 26, 2023

Prior to this change you where not able to capture any reassignable and mutable instances, this limitation was too restricting

Consider the following example where I wanted to have an onUpdate preflight api that sets a member onUpdateCallback. The onUpdateCallback should be called in inflight.

The only way to achieve this is by setting the onUpdateCallback on init.
After this change I should be able to make onUpdateCallback reassignable

bring cloud;
class KeyValueStore {
  bucket: cloud.Bucket;
  var onUpdateCallback : inflight (str): void;
  init(store: cloud.Bucket) {
    this.bucket = store;
    this.onUpdateCallback = inflight (k: str) => {};
  }

  onUpdate(fn: inflight (str):void){
    this.onUpdateCallback = fn;
  }

  inflight get(key: str): Json {
    return this.bucket.getJson(key);
  }
  inflight set(key: str, value: Json): void {
    this.onUpdateCallback(key);
    this.bucket.putJson(key, value);
  }
}

let kv = new KeyValueStore(new cloud.Bucket());
let counter = new cloud.Counter();
kv.onUpdate(inflight (key: str): void => {
  counter.inc(1, key);
});

test "main" {
  kv.set("k", Json { 
    value: "v" 
  });
  kv.get("k");
  kv.get("k");
  kv.get("k2");
  assert(counter.peek("k") == 2);
  assert(counter.peek("k2") == 1);
}

Leftovers

Checklist

  • Title matches Winglang's style guide
  • Description explains motivation and solution
  • Tests added (always)
  • Docs updated (only required for features)
  • Added pr/e2e-full label if this feature requires end-to-end testing

By submitting this pull request, I confirm that my contribution is made under the terms of the Monada Contribution License.

@ekeren ekeren marked this pull request as ready for review June 26, 2023 09:54
@ekeren ekeren requested a review from a team as a code owner June 26, 2023 09:54
@ekeren ekeren changed the title feat: capture reassignable variable and mutable instances feat: capture reassignable variable and mutable objects Jun 26, 2023
@mergify
Copy link
Contributor

mergify bot commented Jun 26, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 5224e27 into main Jun 26, 2023
11 checks passed
@mergify mergify bot deleted the ekeren/inflight-should-capture-mutable branch June 26, 2023 16:28
@mergify
Copy link
Contributor

mergify bot commented Jun 26, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@monadabot
Copy link
Contributor

Congrats! 🚀 This was released in Wing 0.22.18.

mergify bot pushed a commit that referenced this pull request Jul 2, 2023
First pass at rewriting of the concepts doc page on preflight and inflight. The goal is for this doc to be educational but functional, so I started with trying to motivate the concept as quickly as possible (avoiding marketing / history lessons / manifestos about the future of cloud / pitches about the right way to build applications), though I'd be interested in any feedback / suggestions for improving this intro. (We could also remove the intro entirely, and it might actually be better?)

After I tried to come up with a path that goes through the major "mechanics" where the sequence of ideas and code snippets hopefully didn't depend _too_ much on too much knowledge about the standard library resources or about `Json` or optionals etc. I'm also interested in any suggestions for tightening this up / coming up with better examples etc. Since we don't distinguish against capturing reassignable variables or mutable collections as of #3064, I didn't go into much depth about what types of values can be lifted.

Also I moved the content about resource identifiers into the "application tree" doc.

## Checklist

- [ ] Title matches [Winglang's style guide](https://docs.winglang.io/contributing/pull_requests#how-are-pull-request-titles-formatted)
- [ ] Description explains motivation and solution
- [ ] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Monada Contribution License](https://docs.winglang.io/terms-and-policies/contribution-license.html)*.
revitalbarletz pushed a commit that referenced this pull request Jul 3, 2023
First pass at rewriting of the concepts doc page on preflight and inflight. The goal is for this doc to be educational but functional, so I started with trying to motivate the concept as quickly as possible (avoiding marketing / history lessons / manifestos about the future of cloud / pitches about the right way to build applications), though I'd be interested in any feedback / suggestions for improving this intro. (We could also remove the intro entirely, and it might actually be better?)

After I tried to come up with a path that goes through the major "mechanics" where the sequence of ideas and code snippets hopefully didn't depend _too_ much on too much knowledge about the standard library resources or about `Json` or optionals etc. I'm also interested in any suggestions for tightening this up / coming up with better examples etc. Since we don't distinguish against capturing reassignable variables or mutable collections as of #3064, I didn't go into much depth about what types of values can be lifted.

Also I moved the content about resource identifiers into the "application tree" doc.

## Checklist

- [ ] Title matches [Winglang's style guide](https://docs.winglang.io/contributing/pull_requests#how-are-pull-request-titles-formatted)
- [ ] Description explains motivation and solution
- [ ] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Monada Contribution License](https://docs.winglang.io/terms-and-policies/contribution-license.html)*.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants