I am interested in creating an angularJS promise that can work seamlessly with socket.io. Currently, I have a callback function set up to handle the response like this:
function request(event, data, callback) {
socket.emit(event, data);
socket.on(event, function(d) {
socket.off(event);
callback(d);
});
}
As a result, my code looks something like this:
request('myEvent', 'Hello World !', function(data) {
...
});
I am curious if it's possible to implement a promise instead (using the $q service from angular) like so:
request('myEvent', 'Hello World !').then(function(data) {
});
Any insights on how to achieve this would be greatly appreciated! Thank you!