Skip to content

A simple wrapper to allow CocoaScript to execute NSTask / Process asynchronously.

Notifications You must be signed in to change notification settings

mnmly/MochaAsyncTask

Repository files navigation

AsyncTask for CocoaScript

A simple wrapper to allow CocoaScript to execute NSTask (Process) asynchronously.

API

execWithLaunchPath_arguments(launchPath: String, Arguments:[String])

Same arguments as Process

onData(data: String)

[Delegate] Executed when command receives data

onEnd

[Delegate] Executed when command ends

Usage

@import "Debug/MochaJSDelegate.js"

COScript.currentCOScript().setShouldKeepAround_(true)

function loadFramework(pluginRoot, pluginName, className) {
    className = className ? `${pluginName}.${className}` : pluginName
    if ( NSClassFromString( className ) == null ) {
        let mocha = Mocha.sharedRuntime()
        return mocha.loadFrameworkWithName_inDirectory( pluginName, pluginRoot )
    } else {
        return true
    }
}

let result = loadFramework( "./", "MochaAsyncTask", "AsyncTask" )
if ( result == 0 ) log( "Failed to load framework..." )

let AsyncTask = NSClassFromString( "MochaAsyncTask.AsyncTask" )

let task = AsyncTask.alloc().init()
let delegate = new MochaJSDelegate()

delegate.setHandlerForSelector("onData:", (data)=> {
    log(data)
})

delegate.setHandlerForSelector("onEnd", (data)=> {
    log("ENDED")
})

task.setDelegate( delegate.getClassInstance() )
task.execWithLaunchPath_arguments("/usr/bin/curl", ["https://google.com"])

Development

Make sure you pull its submodules first.

$ git submodule update --init

About

A simple wrapper to allow CocoaScript to execute NSTask / Process asynchronously.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published