diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-06-01 03:30:39 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-06-01 03:30:39 +0200 |
| commit | 964ac7009e6db5a06233bdc07fa63778eebf2db7 (patch) | |
| tree | 960ceb019514f960a6597b9b282baf4d5cd77607 /app/client/socket/socket.system.js | |
| parent | dd31a7b9a3af167808b04ffe2af3a66af8b17c33 (diff) | |
async commands!!
Diffstat (limited to 'app/client/socket/socket.system.js')
| -rw-r--r-- | app/client/socket/socket.system.js | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/app/client/socket/socket.system.js b/app/client/socket/socket.system.js index a3c4f15..11cb44c 100644 --- a/app/client/socket/socket.system.js +++ b/app/client/socket/socket.system.js @@ -1,6 +1,6 @@ import { dispatch } from '../store' import types from '../types' - +import uuidv1 from 'uuid/v1' import { socket } from './socket.connection' socket.on('system_res', (data) => { @@ -28,11 +28,18 @@ socket.on('system_res', (data) => { type: data.rpc_connected ? types.system.rpc_connected : types.system.rpc_disconnected, runner: data.runner, }) - case 'command_output': - return dispatch({ - type: types.system.command_output, - data: data, - }) + // case 'run_system_command': + // return dispatch({ + // type: types.system.command_output, + // data: data, + // }) + // case 'list_directory': + // return dispatch({ + // type: types.system.list_directory, + // data: data, + // }) + // break + default: break } }) @@ -43,3 +50,33 @@ export function run_system_command(cmd) { payload: cmd, }) } + +export function list_directory(opt) { + socket.emit('system', { + cmd: 'list_directory', + payload: opt, + }) +} + +export function list_directory_async(opt) { + return syscall_async('list_directory', opt) +} + +export const syscall_async = (tag, payload, ttl=10000) => { + return new Promise( (resolve, reject) => { + const uuid = uuidv1() + const timeout = setTimeout(() => { + socket.off('system_res', cb) + reject('timeout') + }, ttl) + const cb = (data) => { + if (data.uuid === uuid) { + clearTimeout(timeout) + socket.off('system_res', cb) + resolve(data) + } + } + socket.emit('system', { cmd: tag, payload, uuid }) + socket.on('system_res', cb) + }) +} |
