whileTrue: whileFalse:

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

whileTrue: whileFalse:

Adam Crumpton

I want to run a process in the background. I have something like this:

     after := Time readFrom: (ReadStream on: '8AM').
     before := Time readFrom: (ReadStream on: '5PM').

     [[((after < Time now) and: [Time now < before])] whileTrue:
[runTheProcess]] forkAt: 30.


It works out fine (although I would gladly except any criticism), but I
have to run it each morning. Is there anything like:

[runCondition] whileTrue: [doOneSortaThing] whileFalse:
[doAnotherSortaThing] until: [stopCondition]

or do I have nest them:

[[runCondition] whileTrue: [[((after < Time now) and: [Time now <
before])] whileTrue: [runTheProcess]]] forkAt: 30.

any thoughts?

Adam


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
jas
Reply | Threaded
Open this post in threaded view
|

Re: whileTrue: whileFalse:

jas
On 10/21/2014 3:35 PM, Adam Crumpton wrote:

>
> I want to run a process in the background. I have something like this:
>
>     after := Time readFrom: (ReadStream on: '8AM').
>     before := Time readFrom: (ReadStream on: '5PM').
>
>     [[((after < Time now) and: [Time now < before])] whileTrue:
> [runTheProcess]] forkAt: 30.
>
>
> It works out fine (although I would gladly except any criticism), but
> I have to run it each morning. Is there anything like:
>
> [runCondition] whileTrue: [doOneSortaThing] whileFalse:
> [doAnotherSortaThing] until: [stopCondition]

There is now.

BlockClosure>>whileTrue: true0block whileFalse: false0block until:
stop0Block

     [ stop0block value
     ] whileFalse:
             [ self
                  ifTrue: [true0block value]
                 ifFalse: [false0block value]
             ]

Have fun.

-cstb

> or do I have nest them:
>
> [[runCondition] whileTrue: [[((after < Time now) and: [Time now <
> before])] whileTrue: [runTheProcess]]] forkAt: 30.
>
> any thoughts?
>
> Adam
>
>
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>
>

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: whileTrue: whileFalse:

David Buck-2
In reply to this post by Adam Crumpton
I think you're missing a call to value.


BlockClosure>>whileTrue: true0block whileFalse: false0block until: 
stop0Block

     [ stop0block value
     ] whileFalse:
             [ self value
                  ifTrue: [true0block value]
                 ifFalse: [false0block value]
             ]

David

Simberon Incorporated
www.simberon.com



-------- Original message --------
From: jas <[hidden email]>
Date:10-21-2014 7:28 PM (GMT-05:00)
To: Adam Crumpton <[hidden email]>, VWNC <[hidden email]>
Cc:
Subject: Re: [vwnc] whileTrue: whileFalse:

On 10/21/2014 3:35 PM, Adam Crumpton wrote:

>
> I want to run a process in the background. I have something like this:
>
>     after := Time readFrom: (ReadStream on: '8AM').
>     before := Time readFrom: (ReadStream on: '5PM').
>
>     [[((after < Time now) and: [Time now < before])] whileTrue:
> [runTheProcess]] forkAt: 30.
>
>
> It works out fine (although I would gladly except any criticism), but
> I have to run it each morning. Is there anything like:
>
> [runCondition] whileTrue: [doOneSortaThing] whileFalse:
> [doAnotherSortaThing] until: [stopCondition]

There is now.

BlockClosure>>whileTrue: true0block whileFalse: false0block until:
stop0Block

     [ stop0block value
     ] whileFalse:
             [ self
                  ifTrue: [true0block value]
                 ifFalse: [false0block value]
             ]

Have fun.

-cstb

> or do I have nest them:
>
> [[runCondition] whileTrue: [[((after < Time now) and: [Time now <
> before])] whileTrue: [runTheProcess]]] forkAt: 30.
>
> any thoughts?
>
> Adam
>
>
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>
>

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: whileTrue: whileFalse:

Adam Crumpton
I think calling 'self' or 'self value' both work, but calling 'self value' does some sort of inlining optimization. Both blocks and optimization still mystify me somewhat, so if someone wants to enlighten me a little I would listen.


As far as this method goes, though, its just a regular >>whileFalse: method with a nested >>ifTrue:ifFalse: method thats recursive. I would not have put all of the pieces together - especially recursion - anytime soon.

thanks,
Adam

On 10/21/14, 7:05 PM, David Buck wrote:
I think you're missing a call to value.


BlockClosure>>whileTrue: true0block whileFalse: false0block until: 
stop0Block

     [ stop0block value
     ] whileFalse:
             [ self value
                  ifTrue: [true0block value]
                 ifFalse: [false0block value]
             ]

David

Simberon Incorporated



-------- Original message --------
From: jas [hidden email]
Date:10-21-2014 7:28 PM (GMT-05:00)
To: Adam Crumpton [hidden email], VWNC [hidden email]
Cc:
Subject: Re: [vwnc] whileTrue: whileFalse:

On 10/21/2014 3:35 PM, Adam Crumpton wrote:
>
> I want to run a process in the background. I have something like this:
>
>     after := Time readFrom: (ReadStream on: '8AM').
>     before := Time readFrom: (ReadStream on: '5PM').
>
>     [[((after < Time now) and: [Time now < before])] whileTrue:
> [runTheProcess]] forkAt: 30.
>
>
> It works out fine (although I would gladly except any criticism), but
> I have to run it each morning. Is there anything like:
>
> [runCondition] whileTrue: [doOneSortaThing] whileFalse:
> [doAnotherSortaThing] until: [stopCondition]

There is now.

BlockClosure>>whileTrue: true0block whileFalse: false0block until:
stop0Block

     [ stop0block value
     ] whileFalse:
             [ self
                  ifTrue: [true0block value]
                 ifFalse: [false0block value]
             ]

Have fun.

-cstb

> or do I have nest them:
>
> [[runCondition] whileTrue: [[((after < Time now) and: [Time now <
> before])] whileTrue: [runTheProcess]]] forkAt: 30.
>
> any thoughts?
>
> Adam
>
>
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>
>

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: whileTrue: whileFalse:

Paul Baumann
In reply to this post by Adam Crumpton
Adam,

This is closer to the style that I'd use:

myEveningJob_schedule
        | startTime endTime checkEvery |
        startTime := Time readFrom: (ReadStream on: '5PM').
        endTime := Time readFrom: (ReadStream on: '8AM').
        checkEvery := 5 "minutes" * 60000000 "microseconds per minute".
        ^(MyEveningJob := [
                [MyEveningJob == Processor activeProcess] whileTrue: [
                        (Time now between: startTime and: endTime)
                                ifTrue: [self myEveningJob_performEveningWork]
                                ifFalse: [self myEveningJob_performDayWork].
                        (Delay forMicroseconds:: checkEvery - (Time now asNanoseconds  // 1000 \\ checkEvery)) wait.
                ]
        ] newProcess)
                name: 'myEveningJob';
                priority: 30;
                resume

A shared variable named MyEveningJob would be used to control the process loop. Executing the method a second time would allow any prior executions to quietly expire. Use a delay to favor predictable start times and reduce the processor activity that would starve attention from any lower priority processes. The delay above shows how to have work scheduled as #runable at the top of each five minute increment. Whether it actually runs at that precise moment depends on process scheduling that would favor higher priority processes.

Paul Baumann



-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Adam Crumpton
Sent: Tuesday, October 21, 2014 18:36
To: VWNC
Subject: [vwnc] whileTrue: whileFalse:


I want to run a process in the background. I have something like this:

     after := Time readFrom: (ReadStream on: '8AM').
     before := Time readFrom: (ReadStream on: '5PM').

     [[((after < Time now) and: [Time now < before])] whileTrue:
[runTheProcess]] forkAt: 30.


It works out fine (although I would gladly except any criticism), but I have to run it each morning. Is there anything like:

[runCondition] whileTrue: [doOneSortaThing] whileFalse:
[doAnotherSortaThing] until: [stopCondition]

or do I have nest them:

[[runCondition] whileTrue: [[((after < Time now) and: [Time now < before])] whileTrue: [runTheProcess]]] forkAt: 30.

any thoughts?

Adam


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

This message may contain confidential information and is intended for specific recipients unless explicitly noted otherwise. If you have reason to believe you are not an intended recipient of this message, please delete it and notify the sender. This message may not represent the opinion of Intercontinental Exchange, Inc. (ICE), its subsidiaries or affiliates, and does not constitute a contract or guarantee. Unencrypted electronic mail is not secure and the recipient of this message is expected to provide safeguards from viruses and pursue alternate means of communication where privacy or a binding message is desired.

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: whileTrue: whileFalse:

Paul Baumann
In reply to this post by Adam Crumpton
**reposted with bug fixes**

Adam,

This is closer to the style that I'd use:

myEveningJob_schedule
        | startTime endTime checkEvery |
        startTime := Time readFrom: (ReadStream on: '8AM').
        endTime := Time readFrom: (ReadStream on: '5PM').
        checkEvery := 5 "minutes" * 60000000 "microseconds per minute".
        ^(MyEveningJob := [
                [MyEveningJob == Processor activeProcess] whileTrue: [
                        (Time now between: startTime and: endTime)
                                ifTrue: [self myEveningJob_performDayWork]
                                ifFalse: [self myEveningJob_performEveningWork].
                        (Delay forMicroseconds: checkEvery - (Time now asNanoseconds  // 1000 \\ checkEvery)) wait.
                ]
        ] newProcess)
                name: 'myEveningJob';
                priority: 30;
                resume

A shared variable named MyEveningJob would be used to control the process loop. Executing the method a second time would allow any prior executions to quietly expire. Use a delay to favor predictable start times and reduce the processor activity that would starve attention from any lower priority processes. The delay above shows how to have work scheduled as #runable at the top of each five minute increment. Whether it actually runs at that precise moment depends on process scheduling that would favor higher priority processes.

Paul Baumann


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Adam Crumpton
Sent: Tuesday, October 21, 2014 18:36
To: VWNC
Subject: [vwnc] whileTrue: whileFalse:


I want to run a process in the background. I have something like this:

     after := Time readFrom: (ReadStream on: '8AM').
     before := Time readFrom: (ReadStream on: '5PM').

     [[((after < Time now) and: [Time now < before])] whileTrue:
[runTheProcess]] forkAt: 30.


It works out fine (although I would gladly except any criticism), but I have to run it each morning. Is there anything like:

[runCondition] whileTrue: [doOneSortaThing] whileFalse:
[doAnotherSortaThing] until: [stopCondition]

or do I have nest them:

[[runCondition] whileTrue: [[((after < Time now) and: [Time now < before])] whileTrue: [runTheProcess]]] forkAt: 30.

any thoughts?

Adam


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

This message may contain confidential information and is intended for specific recipients unless explicitly noted otherwise. If you have reason to believe you are not an intended recipient of this message, please delete it and notify the sender. This message may not represent the opinion of Intercontinental Exchange, Inc. (ICE), its subsidiaries or affiliates, and does not constitute a contract or guarantee. Unencrypted electronic mail is not secure and the recipient of this message is expected to provide safeguards from viruses and pursue alternate means of communication where privacy or a binding message is desired.

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc