Skip to content

Commit

Permalink
BrFromFuture registers promises
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajKubelka committed Nov 6, 2024
1 parent c01c9f5 commit 11dddda
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/Brick/BrFromFuture.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,35 @@ Class {
'elementStencil',
'elementDataBinder',
'element',
'updater'
'updater',
'configuration'
],
#category : #'Brick-Future - Support'
}

{ #category : #accessing }
BrFromFuture >> configuration [
<return: #AsyncFutureExecutionConfiguration>
^ configuration ifNil: [ configuration := self defaultConfiguration ]
]

{ #category : #accessing }
BrFromFuture >> configuration: aAsyncFutureExecutionConfiguration [
configuration := aAsyncFutureExecutionConfiguration
]

{ #category : #'api - accessing' }
BrFromFuture >> dataBinder: aFromFutureDataBinder [
elementDataBinder := aFromFutureDataBinder asStencilBuilder: BrFromFutureDataBinder
]

{ #category : #initialization }
BrFromFuture >> defaultConfiguration [
^ AsyncFutureExecutionConfiguration new
customGroup: #UI;
highPriority
]

{ #category : #initialization }
BrFromFuture >> defaultLayout [
^ BlFrameLayout new
Expand Down Expand Up @@ -49,6 +68,7 @@ BrFromFuture >> initialize [

{ #category : #'hooks - children' }
BrFromFuture >> onAddedToSceneGraph [
| promise |
super onAddedToSceneGraph.

dataSnapshot isPending
Expand All @@ -65,11 +85,12 @@ BrFromFuture >> onAddedToSceneGraph [
self privateUpdateElement.

futureExecution := future await.
futureExecution
promise := futureExecution
then: [ :aResult | self privateDataSnapshot: (BrFromFutureDataSnapshot new setData: aResult) ]
otherwise: [ :anError |
anError freeze.
self privateDataSnapshot: (BrFromFutureDataSnapshot new setError: anError) ]
self privateDataSnapshot: (BrFromFutureDataSnapshot new setError: anError) ].
element enqueueTask: (BlPromiseTask new promise: promise).
]

{ #category : #private }
Expand Down

0 comments on commit 11dddda

Please sign in to comment.