Future.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5215 531f787a56ab
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4814
62adbb76ba99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4574
diff changeset
     1
"{ Encoding: utf8 }"
62adbb76ba99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4574
diff changeset
     2
1140
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
     3
"
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
     4
 This is a Manchester Goodie protected by copyright.
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
     5
 These conditions are imposed on the whole Goodie, and on any significant
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
     6
 part of it which is separately transmitted or stored:
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
     7
	* You must ensure that every copy includes this notice, and that
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
     8
	  source and author(s) of the material are acknowledged.
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
     9
	* These conditions must be imposed on anyone who receives a copy.
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
    10
	* The material shall not be used for commercial gain without the prior
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
    11
	  written consent of the author(s).
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
    12
 Further information on the copyright conditions may be obtained by
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
    13
 sending electronic mail:
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
    14
	To: goodies-lib@cs.man.ac.uk
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
    15
	Subject: copyright
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
    16
 or by writing to The Smalltalk Goodies Library Manager, Dept of
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
    17
 Computer Science, The University, Manchester M13 9PL, UK
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
    18
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
    19
 (C) Copyright 1992 University of Manchester
2341
36e455705ee6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
    20
 For more information about the Manchester Goodies Library (from which
1140
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
    21
 this file was distributed) send e-mail:
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
    22
	To: goodies-lib@cs.man.ac.uk
2341
36e455705ee6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
    23
	Subject: help
1140
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
    24
"
2341
36e455705ee6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
    25
"{ Package: 'stx:libbasic2' }"
457
c862c91716b6 packages
Claus Gittinger <cg@exept.de>
parents: 351
diff changeset
    26
3848
9a227b37e76b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 3455
diff changeset
    27
"{ NameSpace: Smalltalk }"
9a227b37e76b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 3455
diff changeset
    28
5037
23ce3b9e9dc2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5034
diff changeset
    29
DelayedValue subclass:#Future
23ce3b9e9dc2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5034
diff changeset
    30
	instanceVariableNames:''
1140
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
    31
	classVariableNames:''
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
    32
	poolDictionaries:''
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
    33
	category:'Kernel-Processes'
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
    34
!
a759b5c72c98 Initial revision
claus
parents:
diff changeset
    35
484
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    36
!Future class methodsFor:'documentation'!
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    37
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    38
copyright
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    39
"
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    40
 This is a Manchester Goodie protected by copyright.
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    41
 These conditions are imposed on the whole Goodie, and on any significant
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    42
 part of it which is separately transmitted or stored:
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    43
	* You must ensure that every copy includes this notice, and that
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    44
	  source and author(s) of the material are acknowledged.
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    45
	* These conditions must be imposed on anyone who receives a copy.
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    46
	* The material shall not be used for commercial gain without the prior
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    47
	  written consent of the author(s).
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    48
 Further information on the copyright conditions may be obtained by
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    49
 sending electronic mail:
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    50
	To: goodies-lib@cs.man.ac.uk
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    51
	Subject: copyright
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    52
 or by writing to The Smalltalk Goodies Library Manager, Dept of
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    53
 Computer Science, The University, Manchester M13 9PL, UK
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    54
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    55
 (C) Copyright 1992 University of Manchester
2341
36e455705ee6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
    56
 For more information about the Manchester Goodies Library (from which
484
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    57
 this file was distributed) send e-mail:
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    58
	To: goodies-lib@cs.man.ac.uk
2341
36e455705ee6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
    59
	Subject: help
484
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    60
"
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    61
!
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    62
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    63
documentation
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    64
"
3064
7fe7e32ae4dd class: Future
Claus Gittinger <cg@exept.de>
parents: 2829
diff changeset
    65
    I represent an execution in progress, which will be required some time
7fe7e32ae4dd class: Future
Claus Gittinger <cg@exept.de>
parents: 2829
diff changeset
    66
    in the future.
7fe7e32ae4dd class: Future
Claus Gittinger <cg@exept.de>
parents: 2829
diff changeset
    67
    I will immediately start execution in a separate process,
7fe7e32ae4dd class: Future
Claus Gittinger <cg@exept.de>
parents: 2829
diff changeset
    68
    but delay any messages sent to me, until the execution has completed.
7fe7e32ae4dd class: Future
Claus Gittinger <cg@exept.de>
parents: 2829
diff changeset
    69
    This is useful for time consuming operations (print jobs, compile jobs etc.),
7fe7e32ae4dd class: Future
Claus Gittinger <cg@exept.de>
parents: 2829
diff changeset
    70
    which can be done in the background and the user can do something else
7fe7e32ae4dd class: Future
Claus Gittinger <cg@exept.de>
parents: 2829
diff changeset
    71
    in the meantime. If the computation is finished before the user needs its
7fe7e32ae4dd class: Future
Claus Gittinger <cg@exept.de>
parents: 2829
diff changeset
    72
    value, he is not forced to wait.
7fe7e32ae4dd class: Future
Claus Gittinger <cg@exept.de>
parents: 2829
diff changeset
    73
    If the computation is unfinished, he has to wait for the remaining time only.
1327
cf928a994f81 comments
Claus Gittinger <cg@exept.de>
parents: 1140
diff changeset
    74
2341
36e455705ee6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
    75
    [author:]
3064
7fe7e32ae4dd class: Future
Claus Gittinger <cg@exept.de>
parents: 2829
diff changeset
    76
        tph@cs.man.ac.uk
1516
08829dfb29fe comment
Stefan Vogel <sv@exept.de>
parents: 1514
diff changeset
    77
08829dfb29fe comment
Stefan Vogel <sv@exept.de>
parents: 1514
diff changeset
    78
    [see also:]
3064
7fe7e32ae4dd class: Future
Claus Gittinger <cg@exept.de>
parents: 2829
diff changeset
    79
        Block Lazy LazyValue
484
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    80
"
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    81
!
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    82
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    83
examples
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    84
"
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    85
  Starts evaluating the factorial immediately, but waits until
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    86
  the result is available before printing the answer
2829
e84f89563562 changed:
Stefan Vogel <sv@exept.de>
parents: 2828
diff changeset
    87
                                                                    [exBegin]
484
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    88
    | fac |
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    89
5037
23ce3b9e9dc2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5034
diff changeset
    90
    fac := [10000 factorial printString] futureValue.
484
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    91
    Transcript showCR: 'evaluating factorial...'.
3064
7fe7e32ae4dd class: Future
Claus Gittinger <cg@exept.de>
parents: 2829
diff changeset
    92
    Dialog information:'You can do something useful now...'.
2829
e84f89563562 changed:
Stefan Vogel <sv@exept.de>
parents: 2828
diff changeset
    93
    Transcript showCR: fac
e84f89563562 changed:
Stefan Vogel <sv@exept.de>
parents: 2828
diff changeset
    94
                                                                    [exEnd]
484
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    95
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    96
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    97
  An example illustrating the use of multiple futures and
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    98
  explicit resynchronisation.
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
    99
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   100
  Starts evaluating both factorials immediately, but waits until
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   101
  both blocks have finished before continuing.
2829
e84f89563562 changed:
Stefan Vogel <sv@exept.de>
parents: 2828
diff changeset
   102
                                                                    [exBegin]
484
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   103
    | fac1 fac2 |
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   104
5037
23ce3b9e9dc2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5034
diff changeset
   105
    fac1 := [Transcript showCR: 'Starting fac1.. '. 100000 factorial. Transcript showCR: 'Finished fac1'] futureValue.
23ce3b9e9dc2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5034
diff changeset
   106
    fac2 := [Transcript showCR: 'Starting fac2.. '. 150000 factorial. Transcript showCR: 'Finished fac2'] futureValue.
4006
1bd5da475215 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 3848
diff changeset
   107
    fac2 value.
1bd5da475215 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 3848
diff changeset
   108
    fac1 value.
484
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   109
    Transcript showCR: 'both completed.'.
2829
e84f89563562 changed:
Stefan Vogel <sv@exept.de>
parents: 2828
diff changeset
   110
                                                                    [exEnd]
484
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   111
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   112
  Example showing how arguments may be passed to futures.
2829
e84f89563562 changed:
Stefan Vogel <sv@exept.de>
parents: 2828
diff changeset
   113
                                                                    [exBegin]
484
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   114
    | temp |
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   115
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   116
    temp := [:x :y | 10 * x * y] futureValue: 3 value: 4.
2829
e84f89563562 changed:
Stefan Vogel <sv@exept.de>
parents: 2828
diff changeset
   117
    Transcript  showCR: temp.
484
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   118
2829
e84f89563562 changed:
Stefan Vogel <sv@exept.de>
parents: 2828
diff changeset
   119
                                                                    [exEnd]
484
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   120
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   121
  Claus:
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   122
    The above examples do not really show the power of Futures;
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   123
    they can be useful, whenever some long-time computation is
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   124
    to be done, and some other useful work can be done in the meanwhile.
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   125
    for example:
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   126
3064
7fe7e32ae4dd class: Future
Claus Gittinger <cg@exept.de>
parents: 2829
diff changeset
   127
    Without futures, the inputfile is read before opening the view;
7fe7e32ae4dd class: Future
Claus Gittinger <cg@exept.de>
parents: 2829
diff changeset
   128
    the readTime and view creation times sum up:
2829
e84f89563562 changed:
Stefan Vogel <sv@exept.de>
parents: 2828
diff changeset
   129
                                                                    [exBegin]
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   130
        |p text v t1 t2 tAll|
484
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   131
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   132
        tAll := TimeDuration toRun:[
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   133
            t1 := TimeDuration toRun:[
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   134
                p := PipeStream readingFrom:'ls -l /bin /usr/bin /usr/lib /etc'.
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   135
                text := p contents.
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   136
                p close.
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   137
            ].
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   138
            t2 := TimeDuration toRun:[
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   139
                v := TextView new openAndWait.
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   140
            ].    
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   141
            v contents:text
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   142
        ].
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   143
        Transcript showCR:'Time to read: %1' with:t1.
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   144
        Transcript showCR:'Time to open: %1' with:t2.
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   145
        Transcript showCR:'Time overall: %1' with:tAll.
2829
e84f89563562 changed:
Stefan Vogel <sv@exept.de>
parents: 2828
diff changeset
   146
                                                                    [exEnd]
484
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   147
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   148
    The same here:
2829
e84f89563562 changed:
Stefan Vogel <sv@exept.de>
parents: 2828
diff changeset
   149
                                                                    [exBegin]
e84f89563562 changed:
Stefan Vogel <sv@exept.de>
parents: 2828
diff changeset
   150
        |p text v|
484
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   151
2829
e84f89563562 changed:
Stefan Vogel <sv@exept.de>
parents: 2828
diff changeset
   152
        v := TextView new openAndWait.
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   153
        p := PipeStream readingFrom:'ls -l /bin /usr/bin /usr/lib /etc'.
2829
e84f89563562 changed:
Stefan Vogel <sv@exept.de>
parents: 2828
diff changeset
   154
        text := p contents.
e84f89563562 changed:
Stefan Vogel <sv@exept.de>
parents: 2828
diff changeset
   155
        p close.
e84f89563562 changed:
Stefan Vogel <sv@exept.de>
parents: 2828
diff changeset
   156
        v contents:text
e84f89563562 changed:
Stefan Vogel <sv@exept.de>
parents: 2828
diff changeset
   157
                                                                    [exEnd]
484
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   158
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   159
3064
7fe7e32ae4dd class: Future
Claus Gittinger <cg@exept.de>
parents: 2829
diff changeset
   160
    With futures, the view creation and reading are done in parallel:
7fe7e32ae4dd class: Future
Claus Gittinger <cg@exept.de>
parents: 2829
diff changeset
   161
    (if the windowing system is slow when opening the view, the contents may
7fe7e32ae4dd class: Future
Claus Gittinger <cg@exept.de>
parents: 2829
diff changeset
   162
     be already available - especially on X window systems, where the user
7fe7e32ae4dd class: Future
Claus Gittinger <cg@exept.de>
parents: 2829
diff changeset
   163
     has to provide the window position with the mouse)
2829
e84f89563562 changed:
Stefan Vogel <sv@exept.de>
parents: 2828
diff changeset
   164
                                                                    [exBegin]
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   165
        |p text v t1 t2 tAll|
484
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   166
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   167
        tAll := TimeDuration toRun:[
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   168
            text := [   
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   169
                        |p t|
484
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   170
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   171
                        t1 := TimeDuration toRun:[
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   172
                            p := PipeStream readingFrom:'ls -l /bin /usr/bin /usr/lib /etc'.
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   173
                            t := p contents.
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   174
                            p close.
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   175
                        ].     
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   176
                        t
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   177
                    ] futureValue.
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   178
            t2 := TimeDuration toRun:[
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   179
                v := TextView new openAndWait.
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   180
            ].    
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   181
            v contents:text
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   182
        ].
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   183
        Transcript showCR:'Time to read: %1' with:t1.
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   184
        Transcript showCR:'Time to open: %1' with:t2.
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   185
        Transcript showCR:'Time overall: %1' with:tAll.
2829
e84f89563562 changed:
Stefan Vogel <sv@exept.de>
parents: 2828
diff changeset
   186
                                                                    [exEnd]
484
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   187
"
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   188
! !
d50c08ae6e3d documentation
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   189
1140
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
   190
!Future methodsFor:'evaluating'!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   191
2666
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   192
block:aBlock
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   193
    "Execute aBlock in parallel with whoever called me, 
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   194
     but ensure that any messages sent to me before execution
1514
83af7e61d415 Inherit from protoObject.
Stefan Vogel <sv@exept.de>
parents: 1327
diff changeset
   195
     of the block has terminated are suspended until it has terminated."
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   196
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   197
    self signalSemaphoreAfterForked:aBlock
2666
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   198
4501
d8d48f028be7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4225
diff changeset
   199
    "Modified: / 09-08-2017 / 11:54:19 / cg"
4814
62adbb76ba99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4574
diff changeset
   200
    "Modified: / 12-02-2019 / 20:26:39 / Stefan Vogel"
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   201
    "Modified (comment): / 25-06-2019 / 07:50:12 / Claus Gittinger"
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   202
!
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   203
2666
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   204
block:aBlock value:aValue
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   205
    "Execute aBlock in parallel with whoever called me, 
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   206
     but ensure that any messages sent to me before execution
1514
83af7e61d415 Inherit from protoObject.
Stefan Vogel <sv@exept.de>
parents: 1327
diff changeset
   207
     of the block has terminated are suspended until it has terminated."
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   208
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   209
    self signalSemaphoreAfterForked:[aBlock value:aValue]
2666
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   210
4501
d8d48f028be7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4225
diff changeset
   211
    "Modified: / 09-08-2017 / 11:54:23 / cg"
4814
62adbb76ba99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4574
diff changeset
   212
    "Modified: / 12-02-2019 / 20:27:03 / Stefan Vogel"
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   213
    "Modified (comment): / 25-06-2019 / 07:50:09 / Claus Gittinger"
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   214
!
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   215
2666
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   216
block:aBlock value:value1 value:value2
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   217
    "Execute aBlock in parallel with whoever called me, 
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   218
     but ensure that any messages sent to me before execution
1514
83af7e61d415 Inherit from protoObject.
Stefan Vogel <sv@exept.de>
parents: 1327
diff changeset
   219
     of the block has terminated are suspended until it has terminated."
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   220
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   221
    self signalSemaphoreAfterForked:[aBlock value:value1 value:value2]
2666
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   222
4501
d8d48f028be7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4225
diff changeset
   223
    "Modified: / 09-08-2017 / 11:54:27 / cg"
4814
62adbb76ba99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4574
diff changeset
   224
    "Modified: / 12-02-2019 / 20:27:20 / Stefan Vogel"
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   225
    "Modified (comment): / 25-06-2019 / 07:50:06 / Claus Gittinger"
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   226
!
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   227
2666
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   228
block:aBlock value:value1 value:value2 value:value3
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   229
    "Execute aBlock in parallel with whoever called me, 
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   230
     but ensure that any messages sent to me before execution
1514
83af7e61d415 Inherit from protoObject.
Stefan Vogel <sv@exept.de>
parents: 1327
diff changeset
   231
     of the block has terminated are suspended until it has terminated."
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   232
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   233
    self signalSemaphoreAfterForked:[aBlock value:value1 value:value2 value:value3]
2666
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   234
4501
d8d48f028be7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4225
diff changeset
   235
    "Modified: / 09-08-2017 / 11:54:31 / cg"
4814
62adbb76ba99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4574
diff changeset
   236
    "Modified: / 12-02-2019 / 20:27:31 / Stefan Vogel"
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   237
    "Modified (comment): / 25-06-2019 / 07:50:03 / Claus Gittinger"
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   238
!
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   239
2667
e65a29b55fe1 added: #priority:block:valueWithArguments:
Claus Gittinger <cg@exept.de>
parents: 2666
diff changeset
   240
block:aBlock valueWithArguments:anArray
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   241
    "Execute aBlock in parallel with whoever called me, 
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   242
     but ensure that any messages sent to me before execution
1514
83af7e61d415 Inherit from protoObject.
Stefan Vogel <sv@exept.de>
parents: 1327
diff changeset
   243
     of the block has terminated are suspended until it has terminated."
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   244
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   245
    self signalSemaphoreAfterForked:[aBlock valueWithArguments:anArray]
2667
e65a29b55fe1 added: #priority:block:valueWithArguments:
Claus Gittinger <cg@exept.de>
parents: 2666
diff changeset
   246
4501
d8d48f028be7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4225
diff changeset
   247
    "Modified: / 09-08-2017 / 11:54:34 / cg"
4814
62adbb76ba99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4574
diff changeset
   248
    "Modified: / 12-02-2019 / 20:27:40 / Stefan Vogel"
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   249
    "Modified (comment): / 25-06-2019 / 07:49:52 / Claus Gittinger"
2666
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   250
!
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   251
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   252
priority:prio block:aBlock
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   253
    "Execute aBlock in parallel with whoever called me, 
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   254
     but ensure that any messages sent to me before execution
2666
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   255
     of the block has terminated are suspended until it has terminated."
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   256
5215
531f787a56ab #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 5037
diff changeset
   257
    self signalSemaphoreAfterForked:aBlock atPriority:prio
2666
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   258
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   259
    "Created: / 04-10-2011 / 14:53:21 / cg"
4501
d8d48f028be7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4225
diff changeset
   260
    "Modified: / 09-08-2017 / 11:54:38 / cg"
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   261
    "Modified (comment): / 25-06-2019 / 07:50:20 / Claus Gittinger"
5215
531f787a56ab #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 5037
diff changeset
   262
    "Modified: / 11-09-2019 / 16:19:48 / Stefan Vogel"
2666
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   263
!
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   264
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   265
priority:prio block: aBlock value: aValue
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   266
    "Execute aBlock in parallel with whoever called me, 
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   267
     but ensure that any messages sent to me before execution
2666
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   268
     of the block has terminated are suspended until it has terminated."
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   269
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   270
    self signalSemaphoreAfterForked:[aBlock value:aValue] atPriority:prio
2666
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   271
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   272
    "Created: / 04-10-2011 / 14:53:35 / cg"
4501
d8d48f028be7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4225
diff changeset
   273
    "Modified: / 09-08-2017 / 11:54:41 / cg"
4814
62adbb76ba99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4574
diff changeset
   274
    "Modified: / 12-02-2019 / 20:28:02 / Stefan Vogel"
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   275
    "Modified (comment): / 25-06-2019 / 07:50:23 / Claus Gittinger"
2666
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   276
!
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   277
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   278
priority:prio block:aBlock value:value1 value:value2
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   279
    "Execute aBlock in parallel with whoever called me, 
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   280
     but ensure that any messages sent to me before execution
2666
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   281
     of the block has terminated are suspended until it has terminated."
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   282
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   283
    self signalSemaphoreAfterForked:[aBlock value:value1 value:value2] atPriority:prio
2666
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   284
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   285
    "Created: / 04-10-2011 / 14:54:03 / cg"
4501
d8d48f028be7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4225
diff changeset
   286
    "Modified: / 09-08-2017 / 11:54:44 / cg"
4814
62adbb76ba99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4574
diff changeset
   287
    "Modified: / 12-02-2019 / 20:28:10 / Stefan Vogel"
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   288
    "Modified (comment): / 25-06-2019 / 07:50:26 / Claus Gittinger"
2666
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   289
!
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   290
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   291
priority:prio block:aBlock value:value1 value:value2 value:value3
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   292
    "Execute aBlock in parallel with whoever called me, 
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   293
     but ensure that any messages sent to me before execution
2666
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   294
     of the block has terminated are suspended until it has terminated."
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   295
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   296
    self signalSemaphoreAfterForked:[aBlock value:value1 value:value2 value:value3] atPriority:prio
2666
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   297
Claus Gittinger <cg@exept.de>
parents: 2341
diff changeset
   298
    "Created: / 04-10-2011 / 14:54:51 / cg"
4501
d8d48f028be7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4225
diff changeset
   299
    "Modified: / 09-08-2017 / 11:54:47 / cg"
4814
62adbb76ba99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4574
diff changeset
   300
    "Modified: / 12-02-2019 / 20:28:21 / Stefan Vogel"
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   301
    "Modified (comment): / 25-06-2019 / 07:50:29 / Claus Gittinger"
2667
e65a29b55fe1 added: #priority:block:valueWithArguments:
Claus Gittinger <cg@exept.de>
parents: 2666
diff changeset
   302
!
e65a29b55fe1 added: #priority:block:valueWithArguments:
Claus Gittinger <cg@exept.de>
parents: 2666
diff changeset
   303
e65a29b55fe1 added: #priority:block:valueWithArguments:
Claus Gittinger <cg@exept.de>
parents: 2666
diff changeset
   304
priority:prio block:aBlock valueWithArguments:anArray
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   305
    "Execute aBlock in parallel with whoever called me, 
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   306
     but ensure that any messages sent to me before execution
2667
e65a29b55fe1 added: #priority:block:valueWithArguments:
Claus Gittinger <cg@exept.de>
parents: 2666
diff changeset
   307
     of the block has terminated are suspended until it has terminated."
e65a29b55fe1 added: #priority:block:valueWithArguments:
Claus Gittinger <cg@exept.de>
parents: 2666
diff changeset
   308
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   309
    self signalSemaphoreAfterForked:[aBlock valueWithArguments:anArray] atPriority:prio
2667
e65a29b55fe1 added: #priority:block:valueWithArguments:
Claus Gittinger <cg@exept.de>
parents: 2666
diff changeset
   310
e65a29b55fe1 added: #priority:block:valueWithArguments:
Claus Gittinger <cg@exept.de>
parents: 2666
diff changeset
   311
    "Created: / 04-10-2011 / 14:55:14 / cg"
4501
d8d48f028be7 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4225
diff changeset
   312
    "Modified: / 09-08-2017 / 11:54:50 / cg"
4814
62adbb76ba99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4574
diff changeset
   313
    "Modified: / 12-02-2019 / 20:28:30 / Stefan Vogel"
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   314
    "Modified (comment): / 25-06-2019 / 07:50:32 / Claus Gittinger"
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   315
! !
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   316
5037
23ce3b9e9dc2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5034
diff changeset
   317
!Future methodsFor:'initialization'!
4006
1bd5da475215 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 3848
diff changeset
   318
5037
23ce3b9e9dc2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5034
diff changeset
   319
initializeSemaphore
23ce3b9e9dc2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5034
diff changeset
   320
    "here, the semaphore is created when the evaluation block is defined"
4006
1bd5da475215 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 3848
diff changeset
   321
5037
23ce3b9e9dc2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5034
diff changeset
   322
    "Created: / 25-06-2019 / 10:35:24 / Claus Gittinger"
4006
1bd5da475215 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 3848
diff changeset
   323
! !
1bd5da475215 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 3848
diff changeset
   324
5031
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   325
!Future methodsFor:'private'!
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   326
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   327
signalSemaphoreAfterForked:aBlock
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   328
    "common code for all block:* methods.
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   329
     Execute aBlock in parallel with whatever called me, 
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   330
     and ensure that my private semaphore is signalled at the end."
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   331
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   332
    semaphore := Semaphore name:'Future'.
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   333
    [
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   334
        result := aBlock ensure:[semaphore signal. semaphore := nil.]
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   335
    ] fork
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   336
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   337
    "Created: / 25-06-2019 / 07:32:28 / Claus Gittinger"
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   338
!
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   339
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   340
signalSemaphoreAfterForked:aBlock atPriority:prio
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   341
    "common code for all block:* methods.
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   342
     Execute aBlock in parallel with whatever called me, 
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   343
     and ensure that my private semaphore is signalled at the end."
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   344
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   345
    semaphore := Semaphore name:'Future'.
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   346
    [
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   347
        result := aBlock ensure:[semaphore signal. semaphore := nil.]
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   348
    ] forkAt:prio
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   349
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   350
    "Created: / 25-06-2019 / 07:33:55 / Claus Gittinger"
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   351
! !
0cfe45b14c1a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4814
diff changeset
   352
1140
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
   353
!Future class methodsFor:'documentation'!
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
   354
cbb20fd710fa added #hasValue
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
   355
version
3848
9a227b37e76b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 3455
diff changeset
   356
    ^ '$Header$'
2667
e65a29b55fe1 added: #priority:block:valueWithArguments:
Claus Gittinger <cg@exept.de>
parents: 2666
diff changeset
   357
!
e65a29b55fe1 added: #priority:block:valueWithArguments:
Claus Gittinger <cg@exept.de>
parents: 2666
diff changeset
   358
e65a29b55fe1 added: #priority:block:valueWithArguments:
Claus Gittinger <cg@exept.de>
parents: 2666
diff changeset
   359
version_CVS
3848
9a227b37e76b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 3455
diff changeset
   360
    ^ '$Header$'
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   361
! !
3064
7fe7e32ae4dd class: Future
Claus Gittinger <cg@exept.de>
parents: 2829
diff changeset
   362