[Pharo-project] Implementing a Timer: "newProcessWith: anArray" fails
Hi I do implementing a easy Timer class. The purpose of timer is launch events for UI thread and the process thread too when a interval of time is elapsed. My problem is throwned when I call the message #newProcessWith: from BlockClosure. I pass an array with a parameter, the instance of CLTimer class, which is used in the Closure process for launc the events. A error of not is valid the number of arguments is launched: 'This block accepts 1 argument, but was called with 0 arguments.' I don´t understand very good the problem. I have pass an array with one element, and the Closure receives one parameter too... Basically the code: pvtGetNewProcessBlock ^[:timer || intervalDelay | [timer enabled] whileTrue:[ (Delay forMilliseconds: timer interval) wait. timer enabled ifTrue:[ timer raiseOnElapsedTimeForProcessThread: (timer getProcess). WorldState addDeferredUIMessage:[ timer raiseOnElapsedTimeForUIThread: (timer getProcess) ]. ] ]. ]. pvtStartProcess | processBlock | processBlock := self pvtGetNewProcessBlock. internalProcess := processBlock newProcessWith:{self}. internalProcess resume. PD. Exists some complete doc with the way for work with threads in Pharo/Squeak? I did see time ago a doc of Smalltalk processes, in french language, but I don´t see in Google :( http://forum.world.st/file/n2999831/CLTimer.st CLTimer.st -- View this message in context: http://forum.world.st/Implementing-a-Timer-newProcessWith-anArray-fails-tp29... Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
It works for me: ([:foo | foo + 1 ] newProcessWith: #(10)) resume and ([:foo | foo + 1 ] newProcessWith: {10}) resume works as well. Try put self assert: processBlock argumentCount == 1 in pvtStartProcess. -- Best regards, Igor Stasenko AKA sig.
The assert works good. processBlock numArgs. "returns 1 too" I´m thinking perhaps the problem is Cog VM... it´s possible? If I debug: block := [ :int1 | | int2 | int2 := 2. int1 + int2 ]. block newProcessWith: { 2 }. I get an SimulationGuardException exception... -- View this message in context: http://forum.world.st/Implementing-a-Timer-newProcessWith-anArray-fails-tp29... Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
Now works :| pvtStartProcess internalProcess := [ self pvtCallProcess: self] fork. pvtGetNewProcessBlock ^[:timer || intervalDelay | [timer enabled] whileTrue:[ (Delay forMilliseconds: timer interval) wait. timer enabled ifTrue:[ timer raiseOnElapsedTimeForProcessThread: (timer getProcess). WorldState addDeferredUIMessage:[ timer raiseOnElapsedTimeForUIThread: (timer getProcess) ]. ] ]. ]. pvtCallProcess: oneParam | processBlock | processBlock := self pvtGetNewProcessBlock. processBlock value: oneParam. Anyway I understand than the other way must be go. Something I did bad. Many thanks for the help -- View this message in context: http://forum.world.st/Implementing-a-Timer-newProcessWith-anArray-fails-tp29... Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
On 18 October 2010 14:55, nullPointer <epicfan@gmail.com> wrote:
Now works :|
yes, but probably you found a Cog issue.
pvtStartProcess
    internalProcess := [ self pvtCallProcess: self] fork.
pvtGetNewProcessBlock
    ^[:timer || intervalDelay |
        [timer enabled] whileTrue:[
            (Delay forMilliseconds: timer interval) wait.
            timer enabled ifTrue:[
                timer raiseOnElapsedTimeForProcessThread: (timer getProcess).
                WorldState addDeferredUIMessage:[                     timer raiseOnElapsedTimeForUIThread: (timer getProcess)                 ].             ]         ].     ].
pvtCallProcess: oneParam
    | processBlock |
    processBlock := self pvtGetNewProcessBlock.     processBlock value: oneParam.
Anyway I understand than the other way must be go. Something I did bad.
Many thanks for the help
-- View this message in context: http://forum.world.st/Implementing-a-Timer-newProcessWith-anArray-fails-tp29... Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- Best regards, Igor Stasenko AKA sig.
On Mon, Oct 18, 2010 at 5:07 AM, Igor Stasenko <siguctua@gmail.com> wrote:
On 18 October 2010 14:55, nullPointer <epicfan@gmail.com> wrote:
Now works :|
yes, but probably you found a Cog issue.
What's the definition for BlockClosure>>newProcessWith: ? TIA Eliot
pvtStartProcess
internalProcess := [ self pvtCallProcess: self] fork.
pvtGetNewProcessBlock
^[:timer || intervalDelay |
[timer enabled] whileTrue:[
(Delay forMilliseconds: timer interval) wait.
timer enabled ifTrue:[
timer raiseOnElapsedTimeForProcessThread:
(timer getProcess).
WorldState addDeferredUIMessage:[ timer
raiseOnElapsedTimeForUIThread: (timer getProcess)
]. ] ]. ].
pvtCallProcess: oneParam
| processBlock |
processBlock := self pvtGetNewProcessBlock. processBlock value: oneParam.
Anyway I understand than the other way must be go. Something I did bad.
Many thanks for the help
-- View this message in context:
http://forum.world.st/Implementing-a-Timer-newProcessWith-anArray-fails-tp29...
Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- Best regards, Igor Stasenko AKA sig.
On 18 October 2010 21:04, Eliot Miranda <eliot.miranda@gmail.com> wrote:
On Mon, Oct 18, 2010 at 5:07 AM, Igor Stasenko <siguctua@gmail.com> wrote:
On 18 October 2010 14:55, nullPointer <epicfan@gmail.com> wrote:
Now works :|
yes, but probably you found a Cog issue.
What's the definition for BlockClosure>>newProcessWith: ?
In Pharo it is: newProcessWith: anArray "Answer a Process running the code in the receiver. The receiver's block arguments are bound to the contents of the argument, anArray. The process is not scheduled." <primitive: 19> "Simulation guard" ^Process forContext: [self valueWithArguments: anArray. Processor terminateActive] asContext priority: Processor activePriority In Squeak, this method is missing in BlockClosure, and exists only for BlockContext.
TIA Eliot
pvtStartProcess
    internalProcess := [ self pvtCallProcess: self] fork.
pvtGetNewProcessBlock
    ^[:timer || intervalDelay |
        [timer enabled] whileTrue:[
            (Delay forMilliseconds: timer interval) wait.
            timer enabled ifTrue:[
                timer raiseOnElapsedTimeForProcessThread: (timer getProcess).
                WorldState addDeferredUIMessage:[                     timer raiseOnElapsedTimeForUIThread: (timer getProcess)                 ].             ]         ].     ].
pvtCallProcess: oneParam
    | processBlock |
    processBlock := self pvtGetNewProcessBlock.     processBlock value: oneParam.
Anyway I understand than the other way must be go. Something I did bad.
Many thanks for the help
-- View this message in context: http://forum.world.st/Implementing-a-Timer-newProcessWith-anArray-fails-tp29... Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- Best regards, Igor Stasenko AKA sig.
-- Best regards, Igor Stasenko AKA sig.
participants (3)
-
Eliot Miranda -
Igor Stasenko -
nullPointer