{"action":"opened","issue":{"url":"https://api.github.com/repos/Level/levelup/issues/359","labels_url":"https://api.github.com/repos/Level/levelup/issues/359/labels{/name}","comments_url":"https://api.github.com/repos/Level/levelup/issues/359/comments","events_url":"https://api.github.com/repos/Level/levelup/issues/359/events","html_url":"https://github.com/Level/levelup/issues/359","id":104769611,"number":359,"title":"closing readstream while paused","user":{"login":"timkuijsten","id":321966,"avatar_url":"https://avatars.githubusercontent.com/u/321966?v=3","gravatar_id":"","url":"https://api.github.com/users/timkuijsten","html_url":"https://github.com/timkuijsten","followers_url":"https://api.github.com/users/timkuijsten/followers","following_url":"https://api.github.com/users/timkuijsten/following{/other_user}","gists_url":"https://api.github.com/users/timkuijsten/gists{/gist_id}","starred_url":"https://api.github.com/users/timkuijsten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timkuijsten/subscriptions","organizations_url":"https://api.github.com/users/timkuijsten/orgs","repos_url":"https://api.github.com/users/timkuijsten/repos","events_url":"https://api.github.com/users/timkuijsten/events{/privacy}","received_events_url":"https://api.github.com/users/timkuijsten/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-09-03T19:56:08Z","updated_at":"2015-09-03T19:56:08Z","closed_at":null,"body":"Not sure if this is levelup specific, but I finally found what I thought was #358. It turns out that if a read stream is paused in a data event and asynchronically resumed, the close event might still happen before the resume. This simple test demonstrates the problem:\r\n\r\n    $ cat test.js \r\n    var tmpdir = require('os').tmpdir;\r\n\r\n    var levelup = require('levelup');\r\n\r\n    var path = tmpdir() + '/test_pause';\r\n    console.log('create db in %s', path);\r\n\r\n    levelup(path, function(err, db) {\r\n      if (err) { throw err; }\r\n\r\n      // insert two documents\r\n      var docs = [];\r\n      docs.push({ type: 'put', key: 1, value: 'a' });\r\n      docs.push({ type: 'put', key: 2, value: 'b' });\r\n\r\n      db.batch(docs, function(err) {\r\n        if (err) { throw err; }\r\n\r\n        var it = db.createReadStream();\r\n\r\n        it.on('data', function(item) {\r\n          it.pause();\r\n\r\n          setTimeout(function() {\r\n            console.log('item', item);\r\n            it.resume();\r\n          }, 10);\r\n        });\r\n\r\n        it.on('close', function() {\r\n          console.log('closed');\r\n        });\r\n      });\r\n    });\r\n\r\noutput is as follows:\r\n\r\n    $ node test.js \r\n    create db in /var/folders/tr/mjj_1p394m57_y_51g83jx3c0000gn/T//test_pause\r\n    item { key: '1', value: 'a' }\r\n    closed\r\n    item { key: '2', value: 'b' }\r\n\r\nI would have expected that while a readable stream is paused, no close event will happen until the stream is resumed."}}