-
Notifications
You must be signed in to change notification settings - Fork 115
/
_worker.js
41 lines (37 loc) · 862 Bytes
/
_worker.js
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
import registerPromiseWorker from 'promise-worker/register'
import Sql from './_sql'
const sqlReady = Sql.build()
function processMsg (sql) {
const data = this
switch (data && data.action) {
case 'open':
return sql.open(data.buffer)
case 'reopen':
return sql.open(sql.export())
case 'exec':
return sql.exec(data.sql, data.params)
case 'import':
return sql.import(
data.tabName,
data.data,
data.progressCounterId,
postMessage
)
case 'export':
return sql.export()
case 'close':
return sql.close()
default:
throw new Error('Invalid action : ' + (data && data.action))
}
}
function onError (error) {
return {
error: error.message
}
}
registerPromiseWorker(data => {
return sqlReady
.then(processMsg.bind(data))
.catch(onError)
})