ijs.runtime
Version:
Interactive JavaScript runtime
47 lines (39 loc) • 1.38 kB
JavaScript
// Copyright 2015 Interactive Computing project (https://github.com/interactivecomputing).
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// index.js
// Defines the IJavaScript runtime API
//
var q = require('q'),
request = require('request');
var data = {
html: require('./data/html').create,
image: require('./data/image').create,
script: require('./data/script').create
};
// Turn on improved stack reporting
q.longStackSupport = false;
// Enables running some asynchronous code.
// It provides a deferred object to the specified function that can be resolved
// or rejected upon async completion, and returns a promise representing that
// async result.
function runAsync(fn) {
var deferred = q.defer();
fn(deferred);
return deferred.promise;
}
module.exports = {
async: runAsync,
data: data,
q: q,
request: request
};