mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-19 05:37:53 +00:00
Promisify blink
This commit is contained in:
parent
a8846b37b6
commit
e5684a1c3a
@ -1,15 +1,17 @@
|
||||
fs = require 'fs'
|
||||
Promise = require 'bluebird'
|
||||
fs = Promise.promisifyAll require 'fs'
|
||||
utils = require './utils'
|
||||
express = require 'express'
|
||||
dockerode = require 'dockerode'
|
||||
|
||||
api = express()
|
||||
|
||||
LED_FILE = '/sys/class/leds/led0/brightness'
|
||||
blink = (ms = 200, callback) ->
|
||||
fs.writeFileSync(LED_FILE, 1)
|
||||
setTimeout(->
|
||||
fs.writeFile(LED_FILE, 0, callback)
|
||||
, ms)
|
||||
|
||||
blink = (ms = 200) ->
|
||||
fs.writeFileAsync(LED_FILE, 1)
|
||||
.then(-> utils.delay(ms))
|
||||
.then(-> fs.writeFileAsync(LED_FILE, 0))
|
||||
|
||||
api.post('/blink', (req, res) ->
|
||||
interval = setInterval(blink, 400)
|
||||
|
@ -1,7 +1,7 @@
|
||||
Promise = require('bluebird')
|
||||
fs = Promise.promisifyAll(require('fs'))
|
||||
os = require('os')
|
||||
crypto = require('crypto')
|
||||
Promise = require 'bluebird'
|
||||
fs = Promise.promisifyAll require 'fs'
|
||||
os = require 'os'
|
||||
crypto = require 'crypto'
|
||||
|
||||
# Parses the output of /proc/cpuinfo to find the "Serial : 710abf21" line
|
||||
# or the hostname if there isn't a serial number (when run in dev mode)
|
||||
@ -16,3 +16,5 @@ exports.getDeviceUuid = ->
|
||||
|
||||
return crypto.createHash('sha1').update(serial, 'utf8').digest('hex')
|
||||
)
|
||||
|
||||
exports.delay = (ms) -> new Promise (v) -> setTimeout(v, ms)
|
||||
|
Loading…
Reference in New Issue
Block a user