@@ -5,44 +5,41 @@ class ShoppingApplication usingPlatform: platform = Value (
55)(
66
77 public class Buyer new = (
8- | private customer = 'West Coast Buyers'.
9- private profile = 'West Coast Buyers Profile'.
8+ | private customerInfo = 'West Coast Buyers'.
9+ private profileInfo = 'West Coast Buyers Profile'.
1010 private shoppingCart = Vector new.
1111 |
1212 )(
1313
14- (* Create the teller and send the validation messages to the services *)
15- public checkoutShoppingCart: product account: account shipper: shipper = (
16- | teller listener completionPP prom |
14+ (* Create the teller and send the validation messages to the services *)
15+ public checkoutShoppingCart: product account: account shipper: shipper = (
16+ | teller listener completionPP pConnection |
1717
18- completionPP:: actors createPromisePair.
18+ completionPP:: actors createPromisePair.
1919
20- (* object to notify when the replies are received. It uses as argument a block to execute. *)
21- listener:: Listener new: [:p1 | self <-: placeOrder: completionPP resolver.].
20+ (* object to notify when the replies are received. It uses as argument a block to execute. *)
21+ listener:: Listener new: [:p1 | self <-: placeOrder: completionPP resolver.].
2222
23- teller:: Teller new: (shoppingCart size + 2) listener: listener.
23+ teller:: Teller new: (shoppingCart size + 2) listener: listener.
2424
25- product <-: checkStockConnection.
26-
27- shoppingCart doIndexes:[:i |
28- | partNo |
25+ shoppingCart doIndexes:[:i |
26+ | partNo |
2927 partNo:: shoppingCart at: i.
3028 product <-: partInStock: partNo teller: teller.
31- ].
29+ ].
3230
33- account <-: checkCredit: customer teller: teller.
34- shipper <-: canDeliver: profile teller: teller.
31+ account <-: checkCredit: customerInfo teller: teller.
32+ shipper <-: canDeliver: profileInfo teller: teller.
3533
36- ^ completionPP promise
37- )
34+ ^ completionPP promise
35+ )
3836
39- public placeOrder: resolver = (
37+ public placeOrder: resolver = (
4038 resolver resolve: 'The order has been placed successfully'.
41- )
39+ )
4240
4341 public addItem: item = (
4442 shoppingCart append: item.
45- ('- Items added in Shopping Cart: ' + item) println.
4643 ^ 'ok'
4744 )
4845
@@ -51,11 +48,10 @@ class ShoppingApplication usingPlatform: platform = Value (
5148 public class Listener new: block = (
5249 | private block = block. |
5350 )(
54-
5551 public run = (
5652 ('- All conditions has been met. ' ) println.
5753
58- 1 timesRepeat: [ block value: true] .
54+ block value: true.
5955 )
6056 )
6157
@@ -92,14 +88,10 @@ class ShoppingApplication usingPlatform: platform = Value (
9288 )(
9389
9490 public partInStock: itemNo teller: teller = (
95- ('partInStock true' ) println.
91+ ('partInStock true for ' + itemNo ) println.
9692 ^ teller <-: asyncAnd: true.
9793 )
9894
99- public checkStockConnection = (
100- ^ true
101- )
102-
10395 )
10496
10597 (* Check customer payment info *)
@@ -109,7 +101,6 @@ class ShoppingApplication usingPlatform: platform = Value (
109101 ('checkCredit true') println.
110102 ^ teller <-: asyncAnd: true.
111103 )
112-
113104 )
114105
115106 (* Check availability of shipper *)
@@ -123,7 +114,7 @@ class ShoppingApplication usingPlatform: platform = Value (
123114 )
124115
125116 public main: args = (
126- | checkOutPromise buyer product account shipper cart items asyncPromise promiseItem finalPromise |
117+ | buyer product account shipper cart items asyncPromise finalPromise |
127118
128119 '[SHOPPING APPLICATION] Starting' println.
129120 items:: Vector new.
@@ -137,19 +128,16 @@ class ShoppingApplication usingPlatform: platform = Value (
137128 buyer:: (actors createActorFromValue: Buyer) <-: new.
138129
139130 asyncPromise:: actors async: items do:[: i |
140- | timeoutProm |
141- timeoutProm:: actors createPromisePair.
142-
143- actors after: 1000 do: [
144- buyer <-: addItem: i.
145- timeoutProm resolver resolve: i.
146- ].
147-
148- timeoutProm promise
131+ (buyer <-: addItem: i) whenResolved: [: r |
132+ r = 'ok'
133+ ifTrue:[
134+ ('-items added in shopping cart: ' + i) println.
135+ ].
136+ ].
149137 ].
150138
151139 finalPromise:: asyncPromise whenResolved:[: r |
152- checkOutPromise:: buyer <-: checkoutShoppingCart: product account: account shipper: shipper.
140+ buyer <-: checkoutShoppingCart: product account: account shipper: shipper.
153141 ].
154142
155143 ^ finalPromise whenResolved: [: r2|
0 commit comments