def subscribe(self, callback, preroll_grpos_range=0, preroll_frames=0,
                  preroll_from_frame=None, flag_mask=0):
        pos = None

        if preroll_grpos_range > 0 or preroll_frames > 0:
            raw_pos = self._scan_from_end(preroll_grpos_range,
                                          frames=preroll_frames,
                                          flag_mask=flag_mask)
            if raw_pos is not None:
                pos = raw_pos - self._s.data_offset
        elif preroll_from_frame is not None:
            pos = preroll_from_frame - self._s.data_offset
            if not (0 <= pos < len(self._s.data)):
                e = InvalidFrameNumber('frame %r' % (preroll_from_frame))
                return defer.fail(e)

        if pos is not None:
            for f in self._s.data[pos:]:
                callback(*f)

        self._s.data_listeners.add(callback)
        return defer.succeed(callback)
dataset/ETHPy150Open arkadini/twimp/twimp/server/inmemory.py/IMStream.subscribe/original