author | Martin Kobetic |
Sun, 17 Nov 2013 00:23:18 -0500 | |
changeset 147 | bd6be28aa924 |
parent 109 | 9587e2df7029 |
permissions | -rw-r--r-- |
9 | 1 |
"{ Package: 'stx:goodies/xtreams/terminals' }" |
2 |
||
3 |
"{ NameSpace: Xtreams }" |
|
4 |
||
5 |
ReadStream subclass:#SharedQueueReadStream |
|
6 |
instanceVariableNames:'contentsSpecies' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
25
02e7c3b6f63c
added XtreamsPool to fix DefaultBufferSize; set proper category names
mkobetic
parents:
9
diff
changeset
|
9 |
category:'Xtreams-Terminals' |
9 | 10 |
! |
11 |
||
12 |
SharedQueueReadStream comment:'Read stream on a SharedQueue. Primarily used for data transfer between processes. |
|
13 |
{{{ |
|
14 |
queue := SharedQueue new. |
|
15 |
in := queue reading. |
|
16 |
out := queue writing. |
|
17 |
received := Array new writing. |
|
18 |
done := Semaphore new. |
|
109 | 19 |
consumer := |
9 | 20 |
[ | size | |
109 | 21 |
[ (size := in get) isZero |
9 | 22 |
] whileFalse: [ | word | |
23 |
word := ByteString new: size. |
|
24 |
in read: size into: word. |
|
25 |
received put: word ]. |
|
26 |
done signal. |
|
27 |
] fork. |
|
28 |
#(one two three four) do: [ :word | out put: word size; write: word ]. |
|
29 |
out put: 0. |
|
30 |
done wait. |
|
31 |
received conclusion |
|
32 |
}}} |
|
33 |
||
34 |
Instance Variables |
|
109 | 35 |
contentsSpecies <Class> species for collections of elements of this stream |
9 | 36 |
|
37 |
' |
|
38 |
! |
|
39 |
||
40 |
||
41 |
!SharedQueueReadStream methodsFor:'accessing'! |
|
42 |
||
43 |
get |
|
44 |
^source next |
|
45 |
! |
|
46 |
||
47 |
read: anInteger into: aSequenceableCollection at: startIndex |
|
48 |
startIndex to: startIndex + anInteger - 1 do: [:index | aSequenceableCollection at: index put: source next]. |
|
49 |
^anInteger |
|
50 |
! ! |
|
51 |
||
52 |
!SharedQueueReadStream methodsFor:'initialize-release'! |
|
53 |
||
54 |
close |
|
55 |
! |
|
56 |
||
57 |
contentsSpecies |
|
58 |
^contentsSpecies |
|
59 |
! |
|
60 |
||
61 |
contentsSpecies: aClass |
|
62 |
contentsSpecies := aClass |
|
63 |
! |
|
64 |
||
65 |
on: aSource |
|
66 |
super on: aSource. |
|
67 |
contentsSpecies := Array |
|
68 |
! ! |
|
69 |
||
70 |
!SharedQueueReadStream methodsFor:'private'! |
|
71 |
||
72 |
streamingInsertInto: aWriteStream |
|
73 |
self shouldNotImplement |
|
74 |
! |
|
75 |
||
76 |
streamingWriteInto: aWriteStream |
|
77 |
self shouldNotImplement |
|
78 |
! ! |
|
79 |
||
80 |
!SharedQueueReadStream class methodsFor:'documentation'! |
|
81 |
||
109 | 82 |
version_HG |
83 |
||
84 |
^ '$Changeset: <not expanded> $' |
|
9 | 85 |
! ! |
109 | 86 |