Skip to content
Discussions/App Development/Do we have a sleep `Update` in Daml?Forum ↗

Do we have a sleep `Update` in Daml?

App Development5 posts170 views2 likesLast activity Apr 2022
GY
gyorgybalazsiOP
Apr 2022

I mean can we include a waiting step in an Update, like a contract choice?

I know that we have sleep in Daml Script: Module Daml.Script — Daml SDK 2.1.1 documentation

CO
cocreature
Apr 2022

No, there is no waiting primitive. What are you trying to achieve? Updates are transactional, waiting isn’t going to change the state (including the ledger time) so there isn’t anything you can wait for.

GY
gyorgybalazsi
Apr 2022

I want to send a message to the outside world from the ledger in the form of a ledger action (the recommendation is a nonconsuming choice, but for this question this doesn’t matter, could also be the creation of a Message contract), wait some time, and check weather we got the answer in the form of a contract creation, continue if yes, abort if not.

So basically I want to imitate a monadicly composable HTTP call.

I was thinking about faking the sleep in the form of unnecessary lookups, which is of course not reliable in terms of waiting time. Or some computation with big numbers.

CO
cocreature
Apr 2022
gyorgybalazsi:

wait some time, and check weather we got the answer in the form of a contract creation, continue if yes, abort if not.

This is not going to work. The ledger state observed within an Update does not change over time, you get a consistent ledger snapshot. If the contract didn’t exist at the start of interpretation it’s not going to exist at any point later (unless you create it within the transaction ofc).

If you’re talking to services outside of your Daml ledger you necessarily have to give up on transactionality & use multiple transactions, e.g., first create the message, then wait on the client side until the contract exists and then submit another transaction that uses it.

GY
gyorgybalazsi
Apr 2022

Yes, thanks, this clarifies the situation.

← Back to Discussions