The Trunk: Kernel-tonyg.1152.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Kernel-tonyg.1152.mcz

commits-2
Tony Garnock-Jones uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-tonyg.1152.mcz

==================== Summary ====================

Name: Kernel-tonyg.1152
Author: tonyg
Time: 11 February 2018, 4:07:32.778194 pm
UUID: 3e6a5937-c9a5-4991-b9d7-c0e023cf75e3
Ancestors: Kernel-tonyg.1151

Clear out Promise rejecters and resolvers once the promise settles - already-fired callbacks will not be needed again, and if not cleared out, hang around forever, causing problems for long-lived, reusable promises.

=============== Diff against Kernel-tonyg.1151 ===============

Item was changed:
  ----- Method: Promise>>rejectWith: (in category 'resolving') -----
  rejectWith: anObject
  "Reject this promise."
  mutex critical: [
+ (state == #pending) ifTrue: [ | worklist |
- (state == #pending) ifTrue: [
  error := anObject.
  state := #rejected.
+ worklist := rejecters.
+ resolvers := #().
+ rejecters := #().
+ worklist do: [:r | self evaluateRejecter: r]]]!
- rejecters do: [:r | self evaluateRejecter: r]]]!

Item was changed:
  ----- Method: Promise>>resolveWith: (in category 'resolving') -----
  resolveWith: arg
  "Resolve this promise. If arg is itself a Promise, make this promise depend upon it,
  as detailed in the Promises/A+ spec:
  https://promisesaplus.com/#the-promise-resolution-procedure"
 
  arg isPromise
  ifTrue: [
  arg whenResolved: [:v | self resolveWith: v].
  arg whenRejected: [:e | self rejectWith: e]]
  ifFalse: [
  mutex critical: [
+ (state == #pending) ifTrue: [ | worklist |
- (state == #pending) ifTrue: [
  value := arg.
  state := #fulfilled.
+ worklist := resolvers.
+ resolvers = #().
+ rejecters := #().
+ worklist do: [:r | self evaluateResolver: r]]]]!
- resolvers do: [:r | self evaluateResolver: r]]]]!

Item was changed:
  ----- Method: Promise>>whenRejected: (in category 'resolving') -----
  whenRejected: aBlock
  "Evaluate aBlock when I am rejected"
  aBlock numArgs <= 1 ifFalse: [self error: 'Must be 0- or 1-argument block'].
+ mutex critical: [
+ (state == #pending)
+ ifTrue: [rejecters := rejecters copyWith: aBlock]
+ ifFalse: [self isRejected ifTrue: [self evaluateRejecter: aBlock]]].
+ ^ nil!
- ^ mutex critical: [
- rejecters := rejecters copyWith: aBlock.
- self isRejected ifTrue:[self evaluateRejecter: aBlock].
- ]!

Item was changed:
  ----- Method: Promise>>whenResolved: (in category 'resolving') -----
  whenResolved: aBlock
  "Evaluate aBlock when I am resolved"
  aBlock numArgs <= 1 ifFalse:[self error: 'Must be 0- or 1-argument block'].
+ mutex critical: [
+ (state == #pending)
+ ifTrue: [resolvers := resolvers copyWith: aBlock]
+ ifFalse: [self isResolved ifTrue: [self evaluateResolver: aBlock]]].
+ ^ nil!
- ^ mutex critical: [
- resolvers := resolvers copyWith: aBlock.
- self isResolved ifTrue:[self evaluateResolver: aBlock].
- ]!