Wait for activity to finish before next FOR loop

Paul Mulroney pmulroney at logicaldevelopments.com.au
Mon Jul 25 14:41:36 UTC 2022

Hi Michael, Martin,

You could also not use a For loop, and use the $completed() method to trigger the next send.  That way, it frees up the main thread and your users don't have to sit there watching it ...

We created a "Mail Queue" by inserting each email to send as a record in a database.  The SMTP worker then picks up the first unsent message from the queue and sends it.  When the complete method fires, it looks for another unsent message and then restarts the process over.  If there are no more messages, then the queue stops.

It took a little fiddling to get it to work, but now if Omnis crashes in the middle, it knows how to pickup where it left off.


> On 23 Jul 2022, at 1:47 am, Michael Houlberg <michael at houlbergdevelopment.com> wrote:
> Martin,
> I’ve just started doing the same thing.  I use $cinst.$run instead of $cinst.$start to run it in the main thread.  In this way, it isn’t a background process which is what’s causing the problem.
> Michael Houlberg
> Houlberg Development, LLC
> Sent from my iPad
>> On Jul 22, 2022, at 10:10 AM, Martin Obongita via omnisdev-en <omnisdev-en at lists.omnis-dev.com> wrote:
>> Hi $Listers,
>> I have a FOR loop that runs through a list and sends emails.The problem I have is that the next line in the list is loaded and sent before the previous line has finished emaling.Therefore the email process is cancelled.
>> I'm short of wits on how I could delay or check for a flag to indicate that the process has finished before the next FOR loop begins.
>> $construct
>> Calculate iFileListLineCount as lFileList.$linecount
>> For iFileListLineNum from 1 to iFileListLineCount step 1
>> Calculate iToReceiver as lFileList.[iFileListLineNum].email
>> Calculate iPath as lFileList.[iFileListLineNum].FilePath
>> Calculate iFilename as lFileList.[iFileListLineNum].name
>> Do $cwind.$setFileListInfoRow(iToReceiver,iPath,iFilename)
>> Do $cinst.$start
>> End For
>> As you can see from this method, the next FOR loop will run before the DO $cinst.$start is complete.
>> I have read the documentation and I'm not sure if I could use Object Reference.Has anyone used ObjRef in this case or there is a cleaner code that can solve this?
>> Kind regards,Martin O.
>> _____________________________________________________________
>> Manage your list subscriptions at https://lists.omnis-dev.com
>> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com 
> _____________________________________________________________
> Manage your list subscriptions at https://lists.omnis-dev.com
> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com 

A bargain is something you don't need at a price you can't resist.
Paul W. Mulroney                                            We Don't Do Simple Pty Ltd 
pmulroney at logicaldevelopments.com.au       Trading as Logical Developments
www.logicaldevelopments.com.au                   ACN 161 009 374 
Ph: +61 8 9458 3889                                       86 Coolgardie Street
                                                                         BENTLEY  WA  6102

More information about the omnisdev-en mailing list