sorry for not replying. i switched to Autobahn|Python.

there i just have to this:

```python
class CancallableProtocol(WebSocketServerProtocol):
    task = None
    def onMessage(self, payload, isBinary):
        if data == 'cancel' and self.task:
             if self.task.done():
                  print('already done', self.task.result())
             else:
                  print('cancelling')
                  self.task.set_result('{"cancelled": true}')
                  self.task = None
        elif not self.task:
            self.task = asyncio.async(self.do_task(payload))
            result = yield from self.task
            self.sendMessage(result)
        else:
            print('multiple tasks not yet implemented')
    
    def do_task(self, data):
        ...
```

a shame about the camelCase, though :)

Reply via email to