'use strict';
const express = require('express');
const bodyParser = require('body-parser');
const uuid = require('uuid');
class Some {
constructor() {
this.id = uuid();
this.timer = setInterval(() => {
console.log('чем-то гажу в консоль');
}, 1000 * 1)
}
stop() {
clearInterval(this.timer);
}
}
const pool = {};
const app = express();
app.use(bodyParser.json());
app.route('/')
.post((req, res) => {
const some = new Some();
pool[some.id] = some;
res.json({
message: 'created'
});
})
.delete((req, res) => {
const id = req.body.id;
if (id in pool) {
pool[id].stop();
delete pool[id];
res.json({message: 'deleted'});
} else {
res.json({message: 'cannot delete'});
}
});
const pool = 12; pool = 42;
. Просто они не такие, как, скажем в Haskell.