So, if we scroll to the top, we can see that we got an async function that is op write file. Then we got op fetch, op remove file, and op read file. These are the four functions that were also defined in our JavaScript runtime code. So, you got read file here, write file here, remove file, and fetch.
Let's just use one of them as an example to provide our opposite timeout. I'm going to start with defining the op attribute. The op attribute is coming from Deno. So, this is something we provided for you. Our opposite timeout will return a result. This will be just identity, and then return any error, but we don't really need this error here, but let's just keep it. So, the return value will be okay, and now let's actually do the fun part.
We need to somehow sleep for given delay, which I haven't passed here yet. So, we get delay, which will be U64, and now I'm going to leverage the fantastic ecosystem of fast grades to actually asynchronously wait for the given delay. So, I'm going to use Tokyo for that, which we already used in another API. So, I'm going to use Tokyo, time, delay, sleep, and now I need to pass a duration. Duration comes from STD time duration, and now I need to create it from milliseconds. Sure. Whoops, seems like my IntelliSense is acting up. So, we're going to sleep for a duration taken from the delay variable defined in milliseconds, and then we're just going to await it. So, will this actually be enough? Oh, sure. We don't need to use a question mark here.
So, we defined this in JavaScript. We defined this in Rust. Will it work now? Let's try. Oh, no. It's still not working. Well, even though we created this function, we haven't really told our genocrates to use it, so we need to register it here with our extension, and I'm just going to say OPSET TIMEOUT DECU, and run it again. There we go. We just waited for a second, and we printed something out to a console. That's pretty awesome.
Comments