forked from jamesgao/ipython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommunicate.js
More file actions
96 lines (91 loc) · 2.73 KB
/
Copy pathcommunicate.js
File metadata and controls
96 lines (91 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/***********************************************************************
#-----------------------------------------------------------------------------
# Copyright (c) 2010, IPython Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
This file contains all the AJAX communication functions, used as a library
for most of the other elements
***********************************************************************/
function CometGetter() {
this.queue = []
this.start()
this.request()
}
CometGetter.prototype.request = function () {
var thisObj = this
$.ajax({
success: function (json, status, request) {
if (json != null)
thisObj.complete(json, status, request)
},
error: function (request, status, error) {
statusbar.set("dead")
}
})
}
CometGetter.prototype.complete = function(json, status, request) {
this.request()
if (json.msg_type == "status") {
statusbar.set(json.content.execution_state)
} else if (this.pause) {
this.queue.push(json)
} else {
if (typeof(exec_count) != "undefined" ||
json.msg_type == "execute_reply")
manager.process(json, false, !this.pause)
}
}
CometGetter.prototype.start = function () {
this.pause = false
while (this.queue.length > 0)
manager.process(this.queue.pop())
}
CometGetter.prototype.stop = function () {
this.pause = true
}
function heartbeat() {
$.ajax({
type: "POST",
data: {client_id:client_id, type:"heartbeat"},
success: function() {
setTimeout(heartbeat, 60000)
}
})
}
function execute(code, msg) {
comet.stop()
if (code == "debug" || code == "%debug") {
alert("REP socket not implemented yet, debug mode doesn't work")
throw Exception("Not implemented yet")
}
$.ajax({
type: "POST",
data: {type:"execute", code:code},
success: function(msg_id, status, request) {
if (msg != null)
manager.set(msg, msg_id)
comet.start()
}
})
}
function tabcomplete(code, pos, callback) {
$.ajax({
type:"POST",
data: {type:"complete", code:code, pos:pos},
success: function(json, status, request) {
callback(json.content.matches)
}
})
}
function gethistory(len) {
$.ajax({
type:"POST",
data:{type:"history", index:len},
success: function (json, status, request) {
kernhistory.append(json.content.history)
}
})
}