question

Shuo C2 avatar image
0 Likes"
Shuo C2 asked Jason Lightfoot answered

How can I add a 1min wait to my script with Flexscript?

I'm making calls to an external API which requires some time to initialize the resource I'm asking for after the initial call to create that resource.

Right now I have a piece of code which queries the API for status on the resource in a while loop, which breaks once the resource is ready. However this sends an unnecessary amount of status requests to the API. I would like to add a 60 second delay wait in the while loop before it calls the API again.

Is there a way to replicate this behavior?


FlexSim 21.0.0
flexsim 21.0.0wait timewait
· 4
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

David Seo avatar image David Seo commented ·

@Shuo C2

In your case, 'senddelayedmessage(....)' command is used generally.

You need to use senddelayedmessage command in a trigger you want and the message will be received to On Message trigger.

'Send object' will be able to other receiving object or itself object also. The delay time parameter will be 60 seconds.

0 Likes 0 ·
Shuo C2 avatar image Shuo C2 David Seo commented ·

Thanks for the reply! I forgot to mention I'm sending this request to an external REST API via Flexsim Http.Request, not between any Flexsim objects. Looking at the documentation, it seems to take in a "from" object and a "to" object. Would this function still work out?

0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦ Shuo C2 commented ·

It sounds like you're not using the synchronous method for the request 'sendAndWait()'

1 Like 1 ·
Show more comments

1 Answer

·
Jason Lightfoot avatar image
1 Like"
Jason Lightfoot answered

So the problem is that you are getting a repsonse and it's not the one you want. Is the model running at this point (e.g. very slowly so that you can schedule events in FlexSim time)? You could check against the realtime value to see if 60 real second have elapsed since the last call.

· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Shuo C2 avatar image Shuo C2 commented ·

I've achieved the desired effect using realtime, thanks!

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.