Skip to content

Conversation

jeffrifwaldsmartcontract
Copy link
Contributor

@jeffrifwaldsmartcontract jeffrifwaldsmartcontract commented Sep 20, 2025

  • Proposal for removing reliance on LazyPromise
  • Separating the initial capability call and the result call defers the blocking call until the result function is called/awaited
  • Follows common promise patterns and doesn't rely on user avoiding calling await or then
  • Below are a few other possible comparisons
// A. This is what is proposed in this PR, a single await for the result
const p1 = basicAction.performAction(input1)
const p2 = basicAction.performAction(input2)

const r2 = await p2.result()
const r1 = await p1.result()

// Inline awaits is simple
const inline = await basicAction.performAction(input1).result();

// B. We could also only promise at the action level, which makes it obvious that the result call is synchronous/blocking
const p1 = await basicAction.performAction(input1)
const p2 = await basicAction.performAction(input2)

const r2 = p2.result()
const r1 = p1.result()

// Inline await is still simple
const inline = await basicAction.performAction(input1).result();
// C. We could potentially require awaiting at both levels, like in fetch
// This is arguably the most technically correct pattern, but it is annoying to work with inline/shorthand
const p1 = await basicAction.performAction(input1)
const p2 = await basicAction.performAction(input2)

const r2 = await p2.result()
const r1 = await p1.result()

// Inline awaits are more cumbersome, but this is also how fetch looks
const inline = await (await basicAction.performAction(input1)).result();
// D.  Lastly, we could not use promises at all since neither of these function calls actually benefit from promises
const p1 = basicAction.performAction(input1)
const p2 = basicAction.performAction(input2)

const r2 = p2.result()
const r1 = p1.result()

// Inline requires no await
const inline = basicAction.performAction(input1).result();

In each of the cases above, the code never blocks until calling .result() on an action. This makes it much more intuitive as to what is happening than the magic with a LazyPromise. In order I prefer A, D, C, B, but I'd like to see what @ernest-nowacki and @ryannelsonsmartcontract think about these proposed patterns.

@ernest-nowacki
Copy link
Contributor

This is great!

First of all I never really liked the LazyPromise, just couldn't get out of the box to see how else to solve it. Awesome that you've figured this out!

As for the proposals I would say A or D lands closest with me. D because it feels very much like "it is what is is" - we don't introduce any async where the calls are not async. Kinda like node's api mkdirSync and similar. A because it does feel more intuitive that you would actually await stuff like fetch calls. It's also very familiar with how with native fetch you would call await result.json().

Finally my vote: A.

@jeffrifwaldsmartcontract
Copy link
Contributor Author

A @ernest-nowacki Once #69 is merged I'll update this PR so you can avoid major merge conflict headaches.

@ernest-nowacki
Copy link
Contributor

No worries, I will just merge it now actually as changes aren't so bad - I will merge the one from the generator and then rerun generate scripts 👌

@ernest-nowacki ernest-nowacki merged commit 4d423d4 into main Sep 23, 2025
8 checks passed
@ernest-nowacki ernest-nowacki deleted the DAPP-7422-async-capability branch September 23, 2025 07:36
ernest-nowacki added a commit that referenced this pull request Sep 25, 2025
* Add two workflows to test publishing (#71)

* feat(DAPP-7422): move from lazy promise to async result (#68)

* Reorganize publish scripts (#76)

* add unpublish gh action (#78)

* Use npm (#79)

* Update publish workflow to use zsh (#80)

* use zsh as default (#81)

* Try using zsh absolute path (#82)

* use zsh as default

* one more try getting GH to work

* feat(DAPP-7412): add updates for cre-cli (#73)

* feat(DAPP-7412): update for async result and cre-cli updates

---------

Co-authored-by: Ryan Tinianov <tinianov@live.com>
Co-authored-by: Ernest Nowacki <124677192+ernest-nowacki@users.noreply.github.com>
ernest-nowacki added a commit that referenced this pull request Sep 25, 2025
* Fix logging and secrets standard tests

* Fix Random standard test

* fix last standard test

* Address runtimes merge conflicts (#83)

* Add two workflows to test publishing (#71)

* feat(DAPP-7422): move from lazy promise to async result (#68)

* Reorganize publish scripts (#76)

* add unpublish gh action (#78)

* Use npm (#79)

* Update publish workflow to use zsh (#80)

* use zsh as default (#81)

* Try using zsh absolute path (#82)

* use zsh as default

* one more try getting GH to work

* feat(DAPP-7412): add updates for cre-cli (#73)

* feat(DAPP-7412): update for async result and cre-cli updates

---------

Co-authored-by: Ryan Tinianov <tinianov@live.com>
Co-authored-by: Ernest Nowacki <124677192+ernest-nowacki@users.noreply.github.com>

---------

Co-authored-by: Jeff Rifwald <jeff.rifwald@smartcontract.com>
Co-authored-by: Ryan Tinianov <tinianov@live.com>
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.

2 participants