Skip to content

Commit

Permalink
[feenkcom/gtoolkit#2852] make error handling configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
syrel committed Mar 27, 2024
1 parent 8642e87 commit 91aab58
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/Futures/AsyncFutureExecutionConfiguration.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Class {
'group',
'errorHandler'
],
#classInstVars : [
'defaultErrorHandler'
],
#category : #'Futures-Executor'
}

Expand All @@ -14,6 +17,37 @@ AsyncFutureExecutionConfiguration class >> default [
^ self new
]

{ #category : #accessing }
AsyncFutureExecutionConfiguration class >> defaultErrorHandler [
^ defaultErrorHandler ifNil: [ AsyncNoneErrorHandler uniqueInstance ]
]

{ #category : #accessing }
AsyncFutureExecutionConfiguration class >> initialize [
self normalExceptionHandlingByDefault
]

{ #category : #accessing }
AsyncFutureExecutionConfiguration class >> normalExceptionHandlingByDefault [
"Goes through a normal mechanism of rejecting promises."

defaultErrorHandler := AsyncNoneErrorHandler uniqueInstance
]

{ #category : #accessing }
AsyncFutureExecutionConfiguration class >> notifyExceptionsByDefault [
"Notifies exceptions and continues the normal flow of rejecting promises.
Can slow down execution in case of a large amount if notifications."
defaultErrorHandler := AsyncInformExceptionHandler new
]

{ #category : #accessing }
AsyncFutureExecutionConfiguration class >> passExceptionsByDefault [
"Should only be used for debugging as it influences the normal handling of promises.
Passes exceptions and raises a debugger rather than rejecting promises."
defaultErrorHandler := AsyncPassExceptionHandler new
]

{ #category : #comparing }
AsyncFutureExecutionConfiguration >> = anObject [

Expand Down Expand Up @@ -77,7 +111,7 @@ AsyncFutureExecutionConfiguration >> initialize [

group := AsyncFutureExecutionUnspecifiedGroup uniqueInstance.
priority := AsyncFutureExecutionDefaultPriority uniqueInstance.
errorHandler := AsyncNoneErrorHandler uniqueInstance
errorHandler := self class defaultErrorHandler
]

{ #category : #accessing }
Expand Down
11 changes: 11 additions & 0 deletions src/Futures/AsyncFutureThreadPoolWorker.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ AsyncFutureThreadPoolWorker >> isShuttingDown [
^ monitor critical: [ shouldStop notNil and: [ workerProcess notNil ] ]
]

{ #category : #'api - accessing' }
AsyncFutureThreadPoolWorker >> isWaitingOnSemaphore [
"Return true if the worker is waiting on a semaphore, false otherwise."
<return: #Boolean>

^ monitor critical: [
currentTaskProcess
ifNil: [ false ]
ifNotNil: [ :aProcess | aProcess suspendingList notNil ] ]
]

{ #category : #'api - lifecycle' }
AsyncFutureThreadPoolWorker >> maintanance [
]
Expand Down
19 changes: 19 additions & 0 deletions src/Futures/AsyncInformExceptionHandler.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Class {
#name : #AsyncInformExceptionHandler,
#superclass : #Object,
#traits : 'TAsyncErrorHandler',
#classTraits : 'TAsyncErrorHandler classTrait',
#category : #'Futures-Error Handler'
}

{ #category : #'error handling' }
AsyncInformExceptionHandler >> handleError: anException [
(anException isKindOf: AsyncFutureCancelled)
ifTrue: [ ^ self ].

GtObjectNotificationMessage new
message: anException description;
tooltip: 'Inspect error';
object: anException copy freeze;
registerNotifications
]

0 comments on commit 91aab58

Please sign in to comment.