Future.st
changeset 3064 7fe7e32ae4dd
parent 2829 e84f89563562
child 3455 4467a141f5eb
equal deleted inserted replaced
3063:b4af2ee4ed93 3064:7fe7e32ae4dd
    56 "
    56 "
    57 !
    57 !
    58 
    58 
    59 documentation
    59 documentation
    60 "
    60 "
    61     I represent an execution in progress.
    61     I represent an execution in progress, which will be required some time
    62     I will immediately start execution in a separate process.
    62     in the future.
    63     Any messages sent to me are delayed until execution has completed.'
    63     I will immediately start execution in a separate process,
       
    64     but delay any messages sent to me, until the execution has completed.
       
    65     This is useful for time consuming operations (print jobs, compile jobs etc.),
       
    66     which can be done in the background and the user can do something else
       
    67     in the meantime. If the computation is finished before the user needs its
       
    68     value, he is not forced to wait.
       
    69     If the computation is unfinished, he has to wait for the remaining time only.
    64 
    70 
    65     [author:]
    71     [author:]
    66 	tph@cs.man.ac.uk
    72         tph@cs.man.ac.uk
    67 
    73 
    68     [see also:]
    74     [see also:]
    69 	Block Lazy LazyValue
    75         Block Lazy LazyValue
    70 "
    76 "
    71 !
    77 !
    72 
    78 
    73 examples
    79 examples
    74 "
    80 "
    77                                                                     [exBegin]
    83                                                                     [exBegin]
    78     | fac |
    84     | fac |
    79 
    85 
    80     fac := [5000 factorial] futureValue.
    86     fac := [5000 factorial] futureValue.
    81     Transcript showCR: 'evaluating factorial...'.
    87     Transcript showCR: 'evaluating factorial...'.
       
    88     Dialog information:'You can do something useful now...'.
    82     Transcript showCR: fac
    89     Transcript showCR: fac
    83                                                                     [exEnd]
    90                                                                     [exEnd]
    84 
    91 
    85 
    92 
    86   An example illustrating the use of multiple futures and
    93   An example illustrating the use of multiple futures and
   111     The above examples do not really show the power of Futures;
   118     The above examples do not really show the power of Futures;
   112     they can be useful, whenever some long-time computation is
   119     they can be useful, whenever some long-time computation is
   113     to be done, and some other useful work can be done in the meanwhile.
   120     to be done, and some other useful work can be done in the meanwhile.
   114     for example:
   121     for example:
   115 
   122 
   116     Here, the input is read before - the readTime and view creation
   123     Without futures, the inputfile is read before opening the view;
   117     times sum up:
   124     the readTime and view creation times sum up:
   118                                                                     [exBegin]
   125                                                                     [exBegin]
   119         |p text v|
   126         |p text v|
   120 
   127 
   121         p := PipeStream readingFrom:'ls -l /bin /usr/bin /usr/lib'.
   128         p := PipeStream readingFrom:'ls -l /bin /usr/bin /usr/lib'.
   122         text := p contents.
   129         text := p contents.
   135         p close.
   142         p close.
   136         v contents:text
   143         v contents:text
   137                                                                     [exEnd]
   144                                                                     [exEnd]
   138 
   145 
   139 
   146 
   140     Here, the view creation and reading are done in parallel:
   147     With futures, the view creation and reading are done in parallel:
   141     (if the user is slow when opening the view, the contents may
   148     (if the windowing system is slow when opening the view, the contents may
   142      be already available)
   149      be already available - especially on X window systems, where the user
       
   150      has to provide the window position with the mouse)
   143                                                                     [exBegin]
   151                                                                     [exBegin]
   144         |p text v|
   152         |p text v|
   145 
   153 
   146         text := [   |p t|
   154         text := [   |p t|
   147 
   155 
   349 ! !
   357 ! !
   350 
   358 
   351 !Future class methodsFor:'documentation'!
   359 !Future class methodsFor:'documentation'!
   352 
   360 
   353 version
   361 version
   354     ^ '$Header: /cvs/stx/stx/libbasic2/Future.st,v 1.17 2012-10-19 11:36:05 stefan Exp $'
   362     ^ '$Header: /cvs/stx/stx/libbasic2/Future.st,v 1.18 2013-07-25 09:49:26 cg Exp $'
   355 !
   363 !
   356 
   364 
   357 version_CVS
   365 version_CVS
   358     ^ '$Header: /cvs/stx/stx/libbasic2/Future.st,v 1.17 2012-10-19 11:36:05 stefan Exp $'
   366     ^ '$Header: /cvs/stx/stx/libbasic2/Future.st,v 1.18 2013-07-25 09:49:26 cg Exp $'
   359 ! !
   367 ! !
       
   368