The Artima Developer Community
Sponsored Link

Agile Buzz Forum
The Value of a Delay

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
The Value of a Delay Posted: Aug 18, 2006 7:07 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: The Value of a Delay
Feed Title: Travis Griggs - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/travis-rss.xml
Feed Description: This TAG Line is Extra
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Travis Griggs - Blog

Advertisement

I have some "progress" feedback in the application I'm working on. It ticks off steps as the application starts up. The steps all different durations. Many are slow enough, you can see them go by. They're at a fine enough resolution, that it feels like you're making comfortable progress. But there's a couple that are so fast, they just fly by. So, I'd like to actually ensure that each step takes at least some amount of time. Even if it can really finish faster.

What's so cool about Smalltalk that it has this wonderfully terse definition of a closure, just put code between [ ]'s. I know of no other language that makes it so easy.But what's even cooler is that you can add your own methods to them, to create new forms of execution. Since the message for evaluating a block is value, we'll just add our own valueInAtLeast: aSeconds, implemented as such:

valueInAtLeast: aSeconds
| delay |
delay := Delay untilMicroseconds: Time microsecondClock + (aSeconds * 1000000) rounded.
^self ensure: delay wait

Now we can wrap any arbitrary chunk of code in a block and send valueInAtLeast: to it and be guaranteed it will take that long to execute.

[3 + 4] valueInAtLeast: 1

will compute the classical first Smalltalk expression, but make sure it takes at least 1 second to do it. All those years of making Smalltalk execute faster, and now someone makes it take longer.

Read: The Value of a Delay

Topic: The Great Battery Recall Previous Topic   Next Topic Topic: The suckage continues

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use