Skip to content

Instantly share code, notes, and snippets.

@KevinGutowski
Created March 24, 2021 18:46
Show Gist options
  • Save KevinGutowski/a7fd9eef9bd68ae1ff61c78fe53f5b2b to your computer and use it in GitHub Desktop.
Save KevinGutowski/a7fd9eef9bd68ae1ff61c78fe53f5b2b to your computer and use it in GitHub Desktop.
Async network download
let sketch = require('sketch')
var fiber = require('sketch/async').createFiber()
var url = NSURL.URLWithString("https://github.com/KevinGutowski/Testing/raw/main/Test.sketch")
let session = NSURLSession.sharedSession()
let block = __mocha__.createBlock_function('v32@?0@"NSURL"8@"NSURLResponse"16@"NSError"24', (url,response,error) => {
try {
let docError = MOPointer.alloc().init()
var newDocument = MSDocument.alloc().init();
newDocument.readFromURL_ofType_error(url,"com.bohemiancoding.sketch.drawing", docError);
console.log(sketch.fromNative(newDocument))
} catch(e) {
console.log(e)
}
fiber.cleanup()
}
))
let downloadTask = session.downloadTaskWithURL_completionHandler(url,block)
downloadTask.resume()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment