-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #484 from pharo-graphics/taskitRunner
Add convenience objects to use taskit in Bloc
- Loading branch information
Showing
6 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
Class { | ||
#name : #TKTBlocExamples, | ||
#superclass : #BlExamplesTest, | ||
#category : #'Bloc-Taskit-Tests' | ||
} | ||
|
||
{ #category : #examples } | ||
TKTBlocExamples >> runnerExample [ | ||
<sampleInstance> | ||
" This is equivalent to: | ||
space | ||
enqueueTask: | ||
(BlRepeatedTaskAction new | ||
delay: 200 milliSeconds; | ||
action: [ space root background: Color random ]; | ||
yourself)." | ||
|
||
| space runner | | ||
space := BlSpace new. | ||
space | ||
extent: 100@100; | ||
show. | ||
|
||
runner := TKTBlSpaceRunner on: space. | ||
|
||
[ 17 timesRepeat: [ | ||
runner schedule: [ | ||
space root background: Color random ] asTask. | ||
200 milliSeconds wait ] ] fork. | ||
|
||
^ space | ||
] | ||
|
||
{ #category : #examples } | ||
TKTBlocExamples >> serviceExample [ | ||
<sampleInstance> | ||
"This example is equivalent to: | ||
space | ||
enqueueTask: | ||
(BlRepeatedTaskAction new | ||
delay: 100 milliSeconds; | ||
action: [ space root background: Color random ]; | ||
yourself)." | ||
|
||
| space service | | ||
space := BlSpace new. | ||
space | ||
extent: 100@100; | ||
show. | ||
|
||
service := TKTBlSpaceService on: space. | ||
service step: [ space root background: Color random ]. | ||
service stepDelay: 100 milliSeconds. | ||
service start. | ||
|
||
[ 2 seconds wait. | ||
service stop waitForCompletion: 1 second ] fork. | ||
|
||
^ space | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
Class { | ||
#name : #TKTBlocTest, | ||
#superclass : #BlParameterizedHostTest, | ||
#category : #'Bloc-Taskit-Tests' | ||
} | ||
|
||
{ #category : #running } | ||
TKTBlocTest >> isBeingExecutedInTaskPhase [ | ||
|
||
^ thisContext stack anySatisfy: [ :each | | ||
each receiver class = BlSpaceFrameTaskPhase ] | ||
] | ||
|
||
{ #category : #tests } | ||
TKTBlocTest >> testRunner [ | ||
|
||
| space runner | | ||
space := self newTestingSpace. | ||
space root background: Color green. | ||
|
||
runner := TKTBlSpaceRunner on: space. | ||
runner schedule: [ | ||
space root background: Color red. | ||
self assert: self isBeingExecutedInTaskPhase ] asTask. | ||
|
||
"Task is not executed immediately" | ||
self | ||
assert: space root background paint color | ||
equals: Color green. | ||
"Check again after pulse" | ||
self waitTestingSpaces. | ||
self | ||
assert: space root background paint color | ||
equals: Color red | ||
] | ||
|
||
{ #category : #tests } | ||
TKTBlocTest >> testService [ | ||
|
||
| space service count | | ||
space := self newTestingSpace. | ||
space show. | ||
|
||
service := TKTBlSpaceService on: space. | ||
count := 0. | ||
service step: [ | ||
count := count + 1. | ||
self assert: self isBeingExecutedInTaskPhase ]. | ||
service stepDelay: 50 milliSeconds. | ||
service start. | ||
|
||
0.5 seconds wait. | ||
service stop waitForCompletion: 1 second. | ||
|
||
self assert: count > 1 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Package { #name : #'Bloc-Taskit-Tests' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
" | ||
I'm a TaskIt runner associated with a Bloc space. | ||
" | ||
Class { | ||
#name : #TKTBlSpaceRunner, | ||
#superclass : #TKTRunner, | ||
#instVars : [ | ||
'space' | ||
], | ||
#category : #'Bloc-Taskit-Objects' | ||
} | ||
|
||
{ #category : #'instance creation' } | ||
TKTBlSpaceRunner class >> on: aBlSpace [ | ||
|
||
^ self basicNew | ||
initializeOn: aBlSpace; | ||
yourself | ||
] | ||
|
||
{ #category : #initialization } | ||
TKTBlSpaceRunner >> initializeOn: aBlSpace [ | ||
|
||
self initialize. | ||
|
||
space := aBlSpace | ||
] | ||
|
||
{ #category : #schedulling } | ||
TKTBlSpaceRunner >> scheduleTaskExecution: aTaskExecution [ | ||
|
||
space enqueueTask: | ||
(BlTaskAction new | ||
action: [ self executeTask: aTaskExecution ]; | ||
yourself) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
" | ||
I'm a TaskIt service associated with a Bloc space. | ||
" | ||
Class { | ||
#name : #TKTBlSpaceService, | ||
#superclass : #TKTService, | ||
#instVars : [ | ||
'space', | ||
'actionBlock' | ||
], | ||
#category : #'Bloc-Taskit-Objects' | ||
} | ||
|
||
{ #category : #'instance creation' } | ||
TKTBlSpaceService class >> on: aBlSpace [ | ||
|
||
^ self basicNew | ||
initializeOn: aBlSpace; | ||
yourself | ||
] | ||
|
||
{ #category : #initialization } | ||
TKTBlSpaceService >> initializeOn: aBlSpace [ | ||
|
||
self initialize. | ||
|
||
space := aBlSpace | ||
] | ||
|
||
{ #category : #accessing } | ||
TKTBlSpaceService >> name [ | ||
|
||
^ '{1}/{2}' format: { space. self identityHash } | ||
] | ||
|
||
{ #category : #accessing } | ||
TKTBlSpaceService >> step: aBlockClosure [ | ||
|
||
actionBlock := aBlockClosure | ||
] | ||
|
||
{ #category : #stepping } | ||
TKTBlSpaceService >> stepService [ | ||
|
||
space enqueueTask: | ||
(BlTaskAction new | ||
action: actionBlock; | ||
yourself) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Package { #name : #'Bloc-Taskit' } |