VASmalltalk and Ghostscript – Synchronous and asynchronous usage

I’ve published 0.4 to support either synchronous – or asynchronous usage of that interface.

Synchronous usage is done in the GUI thread (therefore blocking the GUI)

| anInstance anArray |
		
Transcript cr ; show: 'Starting !'.
anArray := Array new: 10.
anArray
  at: 1 put: 'ps2pdf' ;
  at: 2 put: '-dNOPAUSE' ;
  at: 3 put: '-dBATCH' ;
  at: 4 put: '-dSAFER' ;
  at: 5 put: '-sDEVICE=pdfwrite' ;
  at: 6 put: '-sOutputFile=m:\out.pdf' ;
  at: 7 put: '-c' ;
  at: 8 put: '.setpdfwrite';
  at: 9 put: '-f' ;
  at: 10 put: 'm:\escher.ps'.
				
anInstance := MSKGSWrapper new initialize newInstance: nil.
anInstance 						
  initWithArgs: anArray ;
  exit; 
  deleteInstance.

Asynchronous usage can be used if there are lots of documents to be converted in the background or when converting larger documents, where blocking the GUI is not a good idea:

[
  | anInstance anArray |
		
  Transcript cr ; show: 'Starting !'.
  anArray := Array new: 10.
  anArray
    at: 1 put: 'ps2pdf' ;
    at: 2 put: '-dNOPAUSE' ;
    at: 3 put: '-dBATCH' ;
    at: 4 put: '-dSAFER' ;
    at: 5 put: '-sDEVICE=pdfwrite' ;
    at: 6 put: '-sOutputFile=m:\out.pdf' ;
    at: 7 put: '-c' ;
    at: 8 put: '.setpdfwrite';
    at: 9 put: '-f' ;
    at: 10 put: 'm:\escher.ps'.
			
  100 timesRepeat: [  
    anInstance := MSKGSWrapper startWithFutureAndSynchronized.
    anInstance 
      newInstance: nil ;
      initWithArgs: anArray ;
      exit; 
      deleteInstance
  ].
  Transcript cr ; show: 'Finished !'.
] fork
This entry was posted in Smalltalk and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s