The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Smalltalk Daily 8/21/07: Using Promise, Part II

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
Smalltalk Daily 8/21/07: Using Promise, Part II Posted: Aug 21, 2007 2:34 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Smalltalk Daily 8/21/07: Using Promise, Part II
Feed Title: Cincom Smalltalk Blog - Smalltalk with Rants
Feed URL: http://www.cincomsmalltalk.com/rssBlog/rssBlogView.xml
Feed Description: James Robertson comments on Cincom Smalltalk, the Smalltalk development community, and IT trends and issues in general.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Cincom Smalltalk Blog - Smalltalk with Rants

Advertisement

On today's Smalltalk Daily, we take another look at class promise - but at the kind of usage that would be more common. Say you had a set of tasks (like, say, a bunch of HTTP downloads) that had to hapen before the next action could take place. Well, that's what class Promise is for. Here's the example code from today's Screencast:


"collection of urls"
urls := #('http://www.yahoo.com' 'http://www.cincomsmalltalk.com' 'http://www.cincomsmalltalk.com/blog/blogView' 'http://www.podcastalley.com' 'http://www.cincom.com' 'http://www.smalltalkindustrycouncil.org' 'http://www.stic.st' 'http://www.cincomsmalltalk.com/CincomSmalltalkWiki').


"block to download each one"
downloadBlock := [:url | | client response |
	client := HttpClient new.
	response := client get: url.
	Transcript show: 'Downloaded: ', url; cr].

"with Promise"
downloads := urls collect: [:each | [downloadBlock value: each] promise].
downloads do: [:each | each value].



"without Promise"
downloads := urls collect: [:each | | sem |
	sem := Semaphore new.
	[downloadBlock value: each.
	sem signal] fork.
	sem].

downloads do: [:each | each wait].

Technorati Tags:

Read: Smalltalk Daily 8/21/07: Using Promise, Part II

Topic: Whacking the RIAA Upside the Head Previous Topic   Next Topic Topic: Pair Programming techniques

Sponsored Links



Google
  Web Artima.com   

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