Skip to content

Commit b1d308f

Browse files
committed
Working await but no returns
1 parent 76f887d commit b1d308f

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

ipynao/nao_robot.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
class NaoRobotService():
2020
name = None
2121
widget = None
22+
output = None
2223

23-
def __init__(self, widget, service_name):
24+
def __init__(self, widget, output, service_name):
2425
self.name = service_name
2526
self.widget = widget
27+
self.output = output
2628

27-
def create_service_msg(self, method_name, *args, **kwargs):
29+
async def create_service_msg(self, method_name, *args, **kwargs):
2830
self.widget._response = None
2931
data = {}
3032
data["command"] = "callService"
@@ -36,6 +38,14 @@ def create_service_msg(self, method_name, *args, **kwargs):
3638

3739
self.widget.send(data)
3840

41+
try:
42+
self.output.append_stdout("Trying this thing\n")
43+
await self.widget.wait_for_change('counter')
44+
self.output.append_stdout("done waiting\n")
45+
except Exception as e:
46+
print('Something wrong: ', e)
47+
self.output.append_stdout("wrong wrong: " + str(e) + '\n')
48+
3949
def __getattr__(self, method_name):
4050
return lambda *x, **y: self.create_service_msg(method_name, *x, **y)
4151

@@ -123,9 +133,9 @@ def connect(self, ip_address="nao.local", port="80"):
123133
self.send(data)
124134

125135

126-
def service(self, service_name):
136+
def service(self, output, service_name):
127137
data = {}
128138
data["command"] = str("createService")
129139
data["service"] = str(service_name)
130140
self.send(data)
131-
return NaoRobotService(self, service_name)
141+
return NaoRobotService(self, output, service_name)

src/widget.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export class NaoRobotModel extends DOMWidgetModel {
150150
serviceResponse = await servicePromise.then(
151151
(resolution: any) => {
152152
this.changeStatus('Task completed');
153+
this.set('counter', this.get('counter') + 1);
153154
return resolution;
154155
}
155156
).catch(
@@ -158,10 +159,14 @@ export class NaoRobotModel extends DOMWidgetModel {
158159
}
159160
);
160161

161-
console.log("OOO received response ", serviceResponse);
162+
162163
if (serviceResponse !== undefined) {
163-
this.send(serviceResponse);
164+
console.log("OOO received response ", serviceResponse);
165+
// this.send(serviceResponse);
166+
this.set('status', serviceResponse.toString());
164167
}
168+
169+
this.save_changes();
165170
}
166171

167172
async goSleep() {

0 commit comments

Comments
 (0)