A new version of Kernel was added to project The Inbox:
http://source.squeak.org/inbox/Kernel-tonyg.1331.mcz==================== Summary ====================
Name: Kernel-tonyg.1331
Author: tonyg
Time: 4 June 2020, 7:51:24.268037 pm
UUID: b7790e35-7fff-4def-89ef-2a6f8534ca20
Ancestors: Kernel-tonyg.1330
More repairs to Promise to bring it closer to Promise/A+ behaviour.
=============== Diff against Kernel-tonyg.1330 ===============
Item was changed:
----- Method: Promise>>ifRejected: (in category 'monad') -----
ifRejected: errBlock
+ ^ self then: nil ifRejected: errBlock!
- ^ self then: [:ignored | "Do nothing"] ifRejected: errBlock.!
Item was changed:
----- Method: Promise>>then: (in category 'monad') -----
then: resolvedBlock
+ ^ self then: resolvedBlock ifRejected: nil!
- ^ self then: resolvedBlock ifRejected: [:e | "Pass rejection reason along" e].!
Item was changed:
----- Method: Promise>>then:ifRejected: (in category 'monad') -----
then: resolvedBlock ifRejected: errBlock
"Return a Promise that, if it resolves, runs the resolvedBlock. If resolution throws an Exception, it runs the errBlock."
| p |
p := Promise new.
+ resolvedBlock
+ ifNil: [self whenResolved: [:v | p resolveWith: v]]
+ ifNotNil: [
+ self whenResolved: [:v |
+ [p resolveWith: (resolvedBlock value: v)]
+ on: Error do: [:e | p rejectWith: e]]].
+ errBlock
+ ifNil: [self whenRejected: [:e | p rejectWith: e]]
+ ifNotNil: [
+ self whenRejected: [:e |
+ [p resolveWith: (errBlock value: e)]
+ on: Error do: [:e2 | p rejectWith: e2]]].
- self whenResolved: [:v |
- [p resolveWith: (resolvedBlock value: v)]
- on: Error do: [:e | p rejectWith: e]].
- self whenRejected: [:e |
- [p resolveWith: (errBlock value: e)]
- on: Error do: [:e2 | p rejectWith: e2]].
^ p.!