The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Smalltalk Promise

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 Promise Posted: Dec 1, 2008 3:26 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Smalltalk Promise
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

Last week, I brought up class Promise, which makes it easy to code a long running task in a linear fashion - but I just referenced a screencast on it. Today I thought I'd mention how I use Promise in this blog server.

On the sidebar, there's a search box for the blog. Back in the server, this is what actually happens:


	promise := [self 
		actuallySearchFor: searchText 
		inTitle: searchInTitle 
		inText: searchInText] promiseAt: Processor userBackgroundPriority.
	allResults := promise value.

	"other code here"

The search executes as soon as #promiseAt: is sent, but the rest of the method is held up pending the results (queried for by #value) - it's like forking a process and then waiting on a Semaphore, except that all of those mechanics have been wrapped up nicely for you. It makes it very easy to code things that need to happen in a linear fashion, but that you would like to just toss into a different process. As the class comment says:

A Promise represents a value that is being computed by a concurrently executing process. An attempt to read the value of a Promise will wait until the process has finished computing it. If the process terminates with an exception, an attempt to read the value of the Promise will raise the same exception.

Technorati Tags: ,

Read: Smalltalk Promise

Topic: The Energized Way Previous Topic   Next Topic Topic: Dan's Leaving Card

Sponsored Links



Google
  Web Artima.com   

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