refactor co-middleware into co-emitter