Cocoa Based Tasks
Cocoa based tasks have a great advantage when it comes to generating task results in that they can returned native data structures. KosmicTask will receive the result via the bridge and return it to the user.
Thus, Cocoa based tasks can generate complex results using the relevant scripting language native data structures such as arrays and dictionaries. Native dictionaries can be used to provide a fast and efficient way of returning the contents of files as results.
Cocoa Based Application Tasks
Tasks which utilise the Cocoa framework are run as fully fledged Cocoa applications.
Many Cocoa components require the existence of a run loop in order to be utilised to their full potential. Normally, application tasks end when the function that launches them exits. Cocoa based tasks, however, can request that they be allowed to continue running in order to receive further input from runloop sources. When the task determines that it is complete it terminates itself and the task results are returned to the user.
Comparing Standard and Cocoa Based Language Implementations
The differences between the standard and Cocoa variants of any scripting language can be summarised as follows:
- The standard scripting components are less complex and will load faster than the Cocoa variants.
- The Cocoa based scripting components run in-process with their task runner.
- The Cocoa based scripting components will generally use more system resources than the standard components.
We can take the examples of Ruby and RubyCocoa to illustrate the above points.
When a standard Ruby task is executed an instance of the KosmicTaskRubyRunner program is launched (this will be visible in the Activity Monitor application). This program receives the task request from the KosmicTask server component and launches a separate instance of the Ruby command line system (also visible in the Activity Monitor). The task runner passes the task inputs to Ruby and waits for the task results to be returned. When the Ruby instance terminates the task runner formats the task results and returns them to the server component which then transfers them via the network to the user.
When a RubyCocoa task is executed an instance of the KosmicTaskRubyCocoaRunner program is launched. This program executes as a fully fledged Cocoa application complete with runloop. Once successfully launched the task runner loads the Cocoa task into its own process space and executes the designated run function on the designated run class. When the initial run function returns the task runner checks the status of the KosmicTaskController keepTaskAlive property. If the task requests that it be kept alive then the task is allowed to continue executing until it calls the KosmicTaskController stopTask: method. If the task does not request to be kept alive then the task run loop is stopped immediately.